diff --git a/src/ByteStream.php b/src/ByteStream.php index 6190978..daf7908 100644 --- a/src/ByteStream.php +++ b/src/ByteStream.php @@ -6,9 +6,9 @@ use Kryus\Binary\DataType\BinaryValue; use Kryus\Binary\DataType\Byte; use Kryus\Binary\DataType\Dword; -use Kryus\Binary\DataType\SignedByte; -use Kryus\Binary\DataType\SignedDword; -use Kryus\Binary\DataType\SignedWord; +use Kryus\Binary\DataType\UnsignedByte; +use Kryus\Binary\DataType\UnsignedDword; +use Kryus\Binary\DataType\UnsignedWord; use Kryus\Binary\DataType\Word; class ByteStream @@ -143,10 +143,10 @@ public function readByte(?int $endianness = null): Byte /** * @param int|null $endianness - * @return SignedByte + * @return UnsignedByte * @throws \Exception */ - public function readSignedByte(?int $endianness = null): SignedByte + public function readUnsignedByte(?int $endianness = null): UnsignedByte { if (!in_array($endianness, [null, BinaryValue::ENDIANNESS_LITTLE_ENDIAN, BinaryValue::ENDIANNESS_BIG_ENDIAN], true)) { throw new \Exception('Invalid endianness type.'); @@ -154,7 +154,7 @@ public function readSignedByte(?int $endianness = null): SignedByte $binaryValue = $this->readBytes(1); - return new SignedByte($binaryValue, $endianness ?? $this->endianness); + return new UnsignedByte($binaryValue, $endianness ?? $this->endianness); } /** @@ -175,10 +175,10 @@ public function readWord(?int $endianness = null): Word /** * @param int|null $endianness - * @return SignedWord + * @return UnsignedWord * @throws \Exception */ - public function readSignedWord(?int $endianness = null): SignedWord + public function readUnsignedWord(?int $endianness = null): UnsignedWord { if (!in_array($endianness, [null, BinaryValue::ENDIANNESS_LITTLE_ENDIAN, BinaryValue::ENDIANNESS_BIG_ENDIAN], true)) { throw new \Exception('Invalid endianness type.'); @@ -186,7 +186,7 @@ public function readSignedWord(?int $endianness = null): SignedWord $binaryValue = $this->readBytes(2); - return new SignedWord($binaryValue, $endianness ?? $this->endianness); + return new UnsignedWord($binaryValue, $endianness ?? $this->endianness); } /** @@ -207,10 +207,10 @@ public function readDword(?int $endianness = null): Dword /** * @param int|null $endianness - * @return SignedDword + * @return UnsignedDword * @throws \Exception */ - public function readSignedDword(?int $endianness = null): SignedDword + public function readUnsignedDword(?int $endianness = null): UnsignedDword { if (!in_array($endianness, [null, BinaryValue::ENDIANNESS_LITTLE_ENDIAN, BinaryValue::ENDIANNESS_BIG_ENDIAN], true)) { throw new \Exception('Invalid endianness type.'); @@ -218,6 +218,6 @@ public function readSignedDword(?int $endianness = null): SignedDword $binaryValue = $this->readBytes(4); - return new SignedDword($binaryValue, $endianness ?? $this->endianness); + return new UnsignedDword($binaryValue, $endianness ?? $this->endianness); } } diff --git a/src/DataType/BinaryValue.php b/src/DataType/BinaryValue.php index 01c6eb7..4488f55 100644 --- a/src/DataType/BinaryValue.php +++ b/src/DataType/BinaryValue.php @@ -23,7 +23,7 @@ class BinaryValue * @param bool $signed * @throws \Exception */ - public function __construct(string $value, int $endianness = self::ENDIANNESS_LITTLE_ENDIAN, bool $signed = false) + public function __construct(string $value, int $endianness = self::ENDIANNESS_LITTLE_ENDIAN, bool $signed = true) { if (!in_array($endianness, [self::ENDIANNESS_LITTLE_ENDIAN, self::ENDIANNESS_BIG_ENDIAN], true)) { throw new \Exception('Invalid endianness type.'); diff --git a/src/DataType/SignedByte.php b/src/DataType/UnsignedByte.php similarity index 75% rename from src/DataType/SignedByte.php rename to src/DataType/UnsignedByte.php index 45d62ec..a77ddf5 100644 --- a/src/DataType/SignedByte.php +++ b/src/DataType/UnsignedByte.php @@ -3,7 +3,7 @@ namespace Kryus\Binary\DataType; -class SignedByte extends BinaryValue +class UnsignedByte extends BinaryValue { /** * @param string $value @@ -14,9 +14,9 @@ public function __construct(string $value, int $endianness = BinaryValue::ENDIAN { $byteCount = strlen($value); if ($byteCount !== 1) { - throw new \Exception("Invalid byte count of {$byteCount} for value of type Signed Byte."); + throw new \Exception("Invalid byte count of {$byteCount} for value of type Unsigned Byte."); } - parent::__construct($value, $endianness, true); + parent::__construct($value, $endianness, false); } } \ No newline at end of file diff --git a/src/DataType/SignedDword.php b/src/DataType/UnsignedDword.php similarity index 75% rename from src/DataType/SignedDword.php rename to src/DataType/UnsignedDword.php index d393ca8..27cfc3b 100644 --- a/src/DataType/SignedDword.php +++ b/src/DataType/UnsignedDword.php @@ -3,7 +3,7 @@ namespace Kryus\Binary\DataType; -class SignedDword extends BinaryValue +class UnsignedDword extends BinaryValue { /** * @param string $value @@ -14,9 +14,9 @@ public function __construct(string $value, int $endianness = BinaryValue::ENDIAN { $byteCount = strlen($value); if ($byteCount !== 4) { - throw new \Exception("Invalid byte count of {$byteCount} for value of type Signed Dword."); + throw new \Exception("Invalid byte count of {$byteCount} for value of type Unsigned Dword."); } - parent::__construct($value, $endianness, true); + parent::__construct($value, $endianness, false); } } \ No newline at end of file diff --git a/src/DataType/SignedWord.php b/src/DataType/UnsignedWord.php similarity index 75% rename from src/DataType/SignedWord.php rename to src/DataType/UnsignedWord.php index b2fc58d..60ba89d 100644 --- a/src/DataType/SignedWord.php +++ b/src/DataType/UnsignedWord.php @@ -3,7 +3,7 @@ namespace Kryus\Binary\DataType; -class SignedWord extends BinaryValue +class UnsignedWord extends BinaryValue { /** * @param string $value @@ -14,9 +14,9 @@ public function __construct(string $value, int $endianness = BinaryValue::ENDIAN { $byteCount = strlen($value); if ($byteCount !== 2) { - throw new \Exception("Invalid byte count of {$byteCount} for value of type Signed Word."); + throw new \Exception("Invalid byte count of {$byteCount} for value of type Unsigned Word."); } - parent::__construct($value, $endianness, true); + parent::__construct($value, $endianness, false); } } \ No newline at end of file