0
0
mirror of https://github.com/pmmp/ext-encoding.git synced 2025-09-24 20:12:45 +00:00
Files
ext-encoding/tests/writer/get-data-no-reserved.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

24 lines
643 B
PHP

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