diff --git a/src/Protocol/Type/VarIntCompactArray.php b/src/Protocol/Type/VarIntCompactArray.php index 64066f9..0162aa0 100644 --- a/src/Protocol/Type/VarIntCompactArray.php +++ b/src/Protocol/Type/VarIntCompactArray.php @@ -18,7 +18,7 @@ public static function pack(?array $array, ?string $elementType = null, int $api if (null === $array) { $result = VarInt::pack(0); } else { - $length = \count($array) + 1; + $length = \count($array); $result = VarInt::pack($length); foreach ($array as $item) { if (null === $elementType) { @@ -46,7 +46,7 @@ public static function pack(?array $array, ?string $elementType = null, int $api public static function unpack(string $value, ?int &$size, string $elementType, int $apiVersion = 0): ?array { - $length = VarInt::unpack($value, $tmpSize) - 1; + $length = VarInt::unpack($value, $tmpSize); if ($length > 0) { $array = []; $size = 0; diff --git a/tests/TypeTest.php b/tests/TypeTest.php index 8c920a9..8cee5e6 100644 --- a/tests/TypeTest.php +++ b/tests/TypeTest.php @@ -240,7 +240,7 @@ public function testVarIntCompactArray(): void { $exceptedArray = [1, 2, 3]; $encodeResult = VarIntCompactArray::pack($exceptedArray, Int32::class); - $this->assertEquals('08000000010000000200000003', bin2hex($encodeResult)); + $this->assertEquals('06000000010000000200000003', bin2hex($encodeResult)); $this->assertEquals($exceptedArray, VarIntCompactArray::unpack($encodeResult, $size, Int32::class)); $this->assertEquals(13, $size); }