aboutsummaryrefslogtreecommitdiffstats
path: root/vendor/chillerlan/php-qrcode/src/Data/Byte.php
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/chillerlan/php-qrcode/src/Data/Byte.php')
-rw-r--r--vendor/chillerlan/php-qrcode/src/Data/Byte.php67
1 files changed, 54 insertions, 13 deletions
diff --git a/vendor/chillerlan/php-qrcode/src/Data/Byte.php b/vendor/chillerlan/php-qrcode/src/Data/Byte.php
index 02e76a639..10ab85262 100644
--- a/vendor/chillerlan/php-qrcode/src/Data/Byte.php
+++ b/vendor/chillerlan/php-qrcode/src/Data/Byte.php
@@ -2,9 +2,7 @@
/**
* Class Byte
*
- * @filesource Byte.php
* @created 25.11.2015
- * @package chillerlan\QRCode\Data
* @author Smiley <smiley@chillerlan.net>
* @copyright 2015 Smiley
* @license MIT
@@ -12,33 +10,76 @@
namespace chillerlan\QRCode\Data;
-use chillerlan\QRCode\QRCode;
-
-use function ord;
+use chillerlan\QRCode\Common\{BitBuffer, Mode};
+use function chr, ord;
/**
- * Byte mode, ISO-8859-1 or UTF-8
+ * 8-bit Byte mode, ISO-8859-1 or UTF-8
*
* ISO/IEC 18004:2000 Section 8.3.4
* ISO/IEC 18004:2000 Section 8.4.4
*/
-final class Byte extends QRDataAbstract{
+final class Byte extends QRDataModeAbstract{
- protected int $datamode = QRCode::DATA_BYTE;
+ /**
+ * @inheritDoc
+ */
+ public const DATAMODE = Mode::BYTE;
- protected array $lengthBits = [8, 16, 16];
+ /**
+ * @inheritDoc
+ */
+ public function getLengthInBits():int{
+ return ($this->getCharCount() * 8);
+ }
/**
- * @inheritdoc
+ * @inheritDoc
*/
- protected function write(string $data):void{
+ public static function validateString(string $string):bool{
+ return $string !== '';
+ }
+
+ /**
+ * @inheritDoc
+ */
+ public function write(BitBuffer $bitBuffer, int $versionNumber):QRDataModeInterface{
+ $len = $this->getCharCount();
+
+ $bitBuffer
+ ->put(self::DATAMODE, 4)
+ ->put($len, $this::getLengthBits($versionNumber))
+ ;
+
$i = 0;
- while($i < $this->strlen){
- $this->bitBuffer->put(ord($data[$i]), 8);
+ while($i < $len){
+ $bitBuffer->put(ord($this->data[$i]), 8);
$i++;
}
+ return $this;
+ }
+
+ /**
+ * @inheritDoc
+ *
+ * @throws \chillerlan\QRCode\Data\QRCodeDataException
+ */
+ public static function decodeSegment(BitBuffer $bitBuffer, int $versionNumber):string{
+ $length = $bitBuffer->read(self::getLengthBits($versionNumber));
+
+ if($bitBuffer->available() < (8 * $length)){
+ throw new QRCodeDataException('not enough bits available'); // @codeCoverageIgnore
+ }
+
+ $readBytes = '';
+
+ for($i = 0; $i < $length; $i++){
+ $readBytes .= chr($bitBuffer->read(8));
+ }
+
+ return $readBytes;
}
}