mirror of
https://github.com/danog/PHPStruct.git
synced 2024-11-30 04:19:08 +01:00
lib/danog/PHP | ||
tests/danog/PHP | ||
.gitignore | ||
.travis.yml | ||
a | ||
composer.json | ||
example.php | ||
LICENSE | ||
README.md | ||
think |
PHPStruct class
Licensed under MIT.
PHP implementation of Python's struct module.
This library was created to help me develop a client for the mtproto protocol.
The functions and the formats are exactly the ones used in python's struct (https://docs.python.org/2/library/struct.html)
For now custom byte size is not fully supported, as well as p and P formats.
Installation
Install using composer:
composer require danog/phpstruct
Usage
require('vendor/autoload.php');
$struct = new \danog\PHP\Struct();
$pack = $struct->pack("2cxi", "ab", 44);
$unpack = $struct->unpack("2cxi", $pack);
var_dump($unpack);
$count = $struct->calcsize("2cxi");
This library can also be used statically:
require('vendor/autoload.php');
$pack = \danog\PHP\Struct::pack("2cxi", "ab", 44);
$unpack = \danog\PHP\Struct::unpack("2cxi", $pack);
var_dump($unpack);
$count = \danog\PHP\Struct::calcsize("2cxi");