2016-07-05 19:29:13 +02:00
|
|
|
# PHPStruct class
|
2016-07-04 01:43:23 +02:00
|
|
|
|
2016-07-05 20:57:15 +02:00
|
|
|
[![Build Status](https://travis-ci.org/danog/PHPStruct.svg?branch=master)](https://travis-ci.org/danog/PHPStruct)
|
|
|
|
|
2016-07-04 01:43:23 +02:00
|
|
|
Licensed under MIT.
|
|
|
|
|
2016-07-05 19:29:13 +02:00
|
|
|
PHP implementation of Python's struct module.
|
2016-07-04 01:43:23 +02:00
|
|
|
|
|
|
|
This library was created to help me develop a [client for the mtproto protocol](https://github.com/danog/MadelineProto).
|
|
|
|
|
2016-07-12 16:26:54 +02:00
|
|
|
The functions and the formats are exactly the ones used in python's struct
|
|
|
|
(https://docs.python.org/3/library/struct.html)
|
2016-07-04 01:43:23 +02:00
|
|
|
|
2016-07-12 16:26:54 +02:00
|
|
|
For now custom byte size may not work properly on certain machines for the i, I, f and d formats.
|
2016-07-04 01:43:23 +02:00
|
|
|
|
|
|
|
## Installation
|
|
|
|
|
|
|
|
Install using composer:
|
|
|
|
```
|
2016-07-05 19:29:13 +02:00
|
|
|
composer require danog/phpstruct
|
2016-07-04 01:43:23 +02:00
|
|
|
```
|
|
|
|
|
|
|
|
# Usage
|
|
|
|
|
|
|
|
```
|
|
|
|
require('vendor/autoload.php');
|
2016-07-09 21:12:33 +02:00
|
|
|
$struct = new \danog\PHP\Struct();
|
|
|
|
$pack = $struct->pack("2cxi", "ab", 44);
|
|
|
|
$unpack = $struct->unpack("2cxi", $pack);
|
|
|
|
var_dump($unpack);
|
|
|
|
$count = $struct->calcsize("2cxi");
|
2016-07-04 01:43:23 +02:00
|
|
|
```
|
|
|
|
|
2016-07-09 21:12:33 +02:00
|
|
|
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");
|
|
|
|
```
|
|
|
|
|
|
|
|
|
2016-07-04 01:43:23 +02:00
|
|
|
[Daniil Gentili](http://daniil.it)
|