M src/Packable.php => src/Packable.php +2 -1
@@ 4,10 4,11 @@ namespace BareMess;
trait Packable
{
- public function __construct($mess = null)
+ public function __construct(& $mess = null)
{
if ($mess !== null) {
$this->value = unpack(get_called_class()::PACK, $mess)[1];
+ $mess = substr($mess, get_called_class()::BYTES);
}
}
public function mess()
M tests/PrimitivesTest.php => tests/PrimitivesTest.php +6 -2
@@ 65,12 65,16 @@ class PrimitivesTest extends TestCase
$u8->set(255);
$this->assertEquals(255, $u8->get());
$this->assertEquals("\xFF", $u8->mess());
- $u32 = new U32("\xEF\xBE\xAD\xDE");
+ $mess = "\xEF\xBE\xAD\xDE";
+ $u32 = new U32($mess);
+ $this->assertEquals("", $mess);
$this->assertEquals(0xDEADBEEF, $u32->get());
$this->assertEquals("\xEF\xBE\xAD\xDE", $u32->mess());
// On most computers this decade, this will only work as U63.
- $u64 = new U64("\xFF\xFF\xFF\xFF\xFF\xFF\xFF\x7F");
+ $mess = "\xFF\xFF\xFF\xFF\xFF\xFF\xFF\x7F";
+ $u64 = new U64($mess);
+ $this->assertEquals("", $mess);
$this->assertEquals(0x7FFFFFFFFFFFFFFF, $u64->get());
$this->assertEquals("\xFF\xFF\xFF\xFF\xFF\xFF\xFF\x7F", $u64->mess());
}