0
0
mirror of https://github.com/pmmp/ext-encoding.git synced 2025-10-13 18:34:49 +00:00
Files
ext-encoding/tests/varint/read-large-long.phpt
Dylan K. Taylor eb9610a102 Split up ByteBuffer into reader & writer parts
closes #13

This prevents accidentally writing when reading is intended, and vice
versa.
It also allows specialising the APIs and constructors.
2025-09-06 17:12:57 +01:00

34 lines
1003 B
PHP

--TEST--
Test that reading varlongs (> 5 bytes) works correctly
--DESCRIPTION--
The result of the bitwise AND operation has a result of int regardless of the input.
When shifting this to the left by more than 31, the result will be 0 if not explicitly
casted to a larger type before shifting. For varlongs this led to all bits above 32
to be discarded. This test verifies the result of the fix.
--FILE--
<?php
use pmmp\encoding\ByteBufferReader;
use pmmp\encoding\VarInt;
//unsigned
$buffer_2 = str_repeat("\x81", 8) . "\x01";
$buf_2 = new ByteBufferReader($buffer_2);
var_dump(VarInt::readUnsignedLong($buf_2));
//negative signed
$buffer_3 = str_repeat("\x81", 8) . "\x01";
$buf_3 = new ByteBufferReader($buffer_3);
var_dump(VarInt::readSignedLong($buf_3));
//positive signed
$buffer_3 = "\x80" . str_repeat("\x81", 7) . "\x01";
$buf_3 = new ByteBufferReader($buffer_3);
var_dump(VarInt::readSignedLong($buf_3));
?>
--EXPECT--
int(72624976668147841)
int(-36312488334073921)
int(36312488334073920)