File tree Expand file tree Collapse file tree 2 files changed +21
-1
lines changed
Expand file tree Collapse file tree 2 files changed +21
-1
lines changed Original file line number Diff line number Diff line change @@ -58,7 +58,7 @@ function encoder(int $protocolVersion): callable
5858function decode (string $ binaryString ): Either
5959{
6060 $ packedFormat = \sprintf (
61- 'C%s/N%s/A *%s ' ,
61+ 'C%s/N%s/a *%s ' ,
6262 PROTOCOL_ACCESSOR_VERSION ,
6363 PROTOCOL_ACCESSOR_SCHEMA_ID ,
6464 PROTOCOL_ACCESSOR_AVRO
Original file line number Diff line number Diff line change 2323
2424class ProtocolTest extends AbstractFunctionalTestCase
2525{
26+ private const NULL_TERMINATED_HEX = '000000270f303000000000 ' ;
27+ private const NULL_TERMINATED_AVRO_HEX = '303000000000 ' ;
28+
2629 /**
2730 * @test
2831 */
@@ -149,4 +152,21 @@ public function validate_returns_nothing_for_invalid_unpacked(): void
149152
150153 $ this ->assertInstanceOf (Nothing::class, validate (WIRE_FORMAT_PROTOCOL_VERSION , $ decoded ));
151154 }
155+
156+ /**
157+ * @test
158+ */
159+ public function null_terminated_values_unpacked_correctly (): void
160+ {
161+ $ decoded = decode (\hex2bin (self ::NULL_TERMINATED_HEX ));
162+
163+ $ this ->assertInstanceOf (Right::class, $ decoded );
164+
165+ $ unpacked = $ decoded ->extract ();
166+
167+ $ this ->assertIsArray ($ unpacked );
168+ $ this ->assertSame (WIRE_FORMAT_PROTOCOL_VERSION , $ unpacked [PROTOCOL_ACCESSOR_VERSION ]);
169+ $ this ->assertSame (self ::SCHEMA_ID , $ unpacked [PROTOCOL_ACCESSOR_SCHEMA_ID ]);
170+ $ this ->assertSame (self ::NULL_TERMINATED_AVRO_HEX , \bin2hex ($ unpacked [PROTOCOL_ACCESSOR_AVRO ]));
171+ }
152172}
You can’t perform that action at this time.
0 commit comments