mirror of
https://github.com/pmmp/ext-encoding.git
synced 2025-02-28 23:01:32 +00:00
the main benefit of this is the increased difficulty of accidentally using the wrong byte order due to auto complete - now choosing byte order is decided by the first character typed. however, it also reduces the verbosity of the API, though I'm not sure about the 'LE' and 'BE' class names.
32 lines
706 B
PHP
32 lines
706 B
PHP
--TEST--
|
|
read(Un)SignedVar(Int|Long)() must correctly update the internal offset
|
|
--EXTENSIONS--
|
|
encoding
|
|
--FILE--
|
|
<?php
|
|
|
|
use pmmp\encoding\ByteBuffer;
|
|
use pmmp\encoding\VarInt;
|
|
|
|
function test(\Closure $function, int $size) : void{
|
|
$varint = str_repeat(str_repeat("\x80", $size - 1) . "\x00", 3);
|
|
$buffer = new ByteBuffer($varint);
|
|
$originalOffset = $size;
|
|
$buffer->setReadOffset($originalOffset);
|
|
|
|
$function($buffer);
|
|
var_dump($buffer->getReadOffset() === $size + $originalOffset);
|
|
}
|
|
|
|
test(VarInt::readUnsignedInt(...), 5);
|
|
test(VarInt::readSignedInt(...), 5);
|
|
test(VarInt::readUnsignedLong(...), 10);
|
|
test(VarInt::readSignedLong(...), 10);
|
|
|
|
?>
|
|
--EXPECT--
|
|
bool(true)
|
|
bool(true)
|
|
bool(true)
|
|
bool(true)
|