1
0
mirror of https://github.com/pmmp/ext-encoding.git synced 2024-11-23 13:36:25 +00:00
ext-encoding/tests/read-triad.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

32 lines
643 B
PHP

--TEST--
Test that reading triads works correctly
--DESCRIPTION--
Triads require special implementation due to not being a power-of-two size. This opens avenues for extra bugs that must be tested for.
--FILE--
<?php
use pmmp\encoding\ByteBuffer;
use pmmp\encoding\BE;
use pmmp\encoding\LE;
$buffer = new ByteBuffer("\xff\x00\x00");
var_dump(BE::readSignedTriad($buffer));
$buffer->setReadOffset(0);
var_dump(LE::readSignedTriad($buffer));
$buffer->setReadOffset(0);
var_dump(BE::readUnsignedTriad($buffer));
$buffer->setReadOffset(0);
var_dump(LE::readUnsignedTriad($buffer));
?>
--EXPECT--
int(-65536)
int(255)
int(16711680)
int(255)