1
0
mirror of https://github.com/danog/PHPStruct.git synced 2024-11-26 19:54:38 +01:00
Go to file
Daniil Gentili 205365f0eb Add badges
2016-07-15 12:52:32 +02:00
lib/danog/PHP Applied fixes from StyleCI 2016-07-13 14:00:38 -04:00
tests/danog/PHP Fixed behaviour of ? format, fixed tests. 2016-07-13 19:54:12 +02:00
.gitignore First commit (master) 2016-07-04 01:43:23 +02:00
.styleci.yml Added styleci tests and badge 2016-07-13 19:59:59 +02:00
.travis.yml Add badges 2016-07-15 12:52:32 +02:00
composer.json Updated deps, added some badges. 2016-07-15 12:50:26 +02:00
composer.lock Updated dependencies 2016-07-12 16:40:24 +02:00
example.php Applied fixes from StyleCI 2016-07-13 14:00:38 -04:00
LICENSE First commit (master) 2016-07-04 01:43:23 +02:00
README.md Add badges 2016-07-15 12:52:32 +02:00

PHPStruct class

Build Status Codacy Badge Packagist Packagist HHVM StyleCI

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/3/library/struct.html)

For now custom byte size may not work properly on certain machines for the i, I, f and d 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");

Daniil Gentili