mirror of
https://github.com/pmmp/ext-encoding.git
synced 2024-11-23 13:36:25 +00:00
56673dd789
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
643 B
PHP
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)
|
|
|