2016-07-04 01:43:23 +02:00
|
|
|
<?php
|
|
|
|
|
2016-07-06 14:24:07 +02:00
|
|
|
//require('vendor/autoload.php');
|
2016-07-26 16:23:31 +02:00
|
|
|
require 'lib/danog/PHP/StructTools.php';
|
2016-07-28 13:40:22 +02:00
|
|
|
require 'lib/danog/PHP/StructClass.php';
|
2016-07-26 16:23:31 +02:00
|
|
|
require 'lib/danog/PHP/StructException.php';
|
2016-07-13 20:00:38 +02:00
|
|
|
require 'lib/danog/PHP/Struct.php';
|
2016-07-28 15:50:04 +02:00
|
|
|
var_dump(\danog\PHP\Struct::calcsize('>l'));
|
2016-07-26 16:23:31 +02:00
|
|
|
|
2016-07-28 15:34:14 +02:00
|
|
|
// Dynamic usage with format definition on istantiation
|
|
|
|
$struct = new \danog\PHP\StructClass('2cxbxBx?xhxHxixIxlxLxqxQxnxNxfxdx2sx5pP');
|
2016-07-28 15:50:04 +02:00
|
|
|
var_dump($struct->unpack($struct->pack('n', 'v', -127, 100, true, 333, 444, 232423, 234342, 999999, 9999999, -888888888888, 888888888888, 34434, 344434, 2.2343, 3.03424, 'df', 'asdfghjkl', 1283912)));
|
2016-07-08 22:57:46 +02:00
|
|
|
|
2016-07-28 15:34:14 +02:00
|
|
|
// Dynamic usage with format definition on function call
|
|
|
|
$struct = new \danog\PHP\StructClass();
|
2016-07-28 15:50:04 +02:00
|
|
|
var_dump($struct->unpack('2cxbxBx?xhxHxixIxlxLxqxQxnxNxfxdx2sx5pP', $struct->pack('2cxbxBx?xhxHxixIxlxLxqxQxnxNxfxdx2sx5pP', 'n', 'v', -127, 100, true, 333, 444, 232423, 234342, 999999, 999999, -888888888888, 888888888888, 34434, 344434, 2.2343, 3.03424, 'df', 'asdfghjkl', 1283912)));
|
2016-07-28 15:34:14 +02:00
|
|
|
|
|
|
|
// Static usage
|
2016-07-28 15:50:04 +02:00
|
|
|
var_dump(\danog\PHP\Struct::unpack('2cxbxBx?xhxHxixIxlxLxqxQxnxNxfxdx2sx5pP', \danog\PHP\Struct::pack('2cxbxBx?xhxHxixIxlxLxqxQxnxNxfxdx2sx5pP', 'n', 'v', -127, 100, true, 333, 444, 232423, 234342, 999999, 999999, -888888888888, 888888888888, 34434, 344434, 2.2343, 3.03424, 'df', 'asdfghjkl', 1283912)));
|
2016-07-28 15:34:14 +02:00
|
|
|
|
|
|
|
// S'more examples
|
2016-07-26 16:23:31 +02:00
|
|
|
var_dump(\danog\PHP\Struct::calcsize('f'));
|
2016-07-28 19:27:48 +02:00
|
|
|
var_dump(bin2hex(pack('J', 999998999999999)));
|
|
|
|
var_dump(bin2hex(\danog\PHP\Struct::pack('>Q', 999998999999999)));
|