1
0
mirror of https://github.com/pmmp/ext-encoding.git synced 2024-11-27 05:49:01 +00:00
ext-encoding/tests/buffer-to-string.phpt
Dylan K. Taylor 56673dd789
Split Types class into several new classes
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.
2024-04-10 16:34:24 +01:00

24 lines
616 B
PHP

--TEST--
Test that ByteBuffer::toString() doesn't show unused bytes in reserved space
--DESCRIPTION--
ByteBuffer may allocate more bytes than it needs in order to minimize allocations.
--FILE--
<?php
use pmmp\encoding\ByteBuffer;
use pmmp\encoding\BE;
use pmmp\encoding\Byte;
$buffer = new ByteBuffer("");
BE::writeSignedInt($buffer, 0); //first buffer alloc, 4 bytes
Byte::writeSigned($buffer, 0); //second buffer alloc, 8 bytes (used 5)
var_dump(bin2hex($buffer->toString()));
$buffer = new ByteBuffer("aaaaaaaaaa");
var_dump($buffer->toString());
?>
--EXPECT--
string(10) "0000000000"
string(10) "aaaaaaaaaa"