2017 © Pedro Peláez
 

library phpstruct

PHP implementation of python's struct module.

image

danog/phpstruct

PHP implementation of python's struct module.

  • Monday, June 4, 2018
  • by danog
  • Repository
  • 2 Watchers
  • 4 Stars
  • 2,913 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 2 Forks
  • 0 Open issues
  • 16 Versions
  • 1 % Grown

The README.md

PHPStruct class

Build Status Codacy Badge License Packagist download count Packagist HHVM Status StyleCI, (*1)

Licensed under MIT., (*2)

PHP implementation of Python's struct module., (*3)

This library was created to help me develop a client for the mtproto protocol.
It supports php 5.6, php 7 and HHVM., (*4)

The functions and the formats are exactly the ones used in python's struct (https://docs.python.org/3/library/struct.html), (*5)

This library can be used to pack/unpack strings, ints, floats, chars and bools into bytes. It has lots of advantages over PHP's native implementation of pack and unpack, such as:
* Custom byte endianness. * Lots of useful formats that aren't present in the native implementation. * The syntax of the format string of pack and unpack is the same as in python's struct module. * The result of unpack is normal numerically indexed array that starts from 0 like it should. * The result of unpack has type casted values (int for integer formats, bool for boolean formats, float for float formats and string for all of the other formats). * The calcsize function is implemented. * The q and Q formats can be used even on 32 bit systems (the downside is limited precision). * Padding is supported for the @ modifier., (*6)

For now custom byte size may not work properly on certain machines for the f and d formats., (*7)

Installation

Install using composer:, (*8)

composer require danog/phpstruct

Usage

Dynamic (recommended), (*9)

require('vendor/autoload.php');
$struct = new \danog\PHP\StructClass();
$pack = $struct->pack("2cxi", "ab", 44);
$unpack = $struct->unpack("2cxi", $pack);
var_dump($unpack);
$count = $struct->calcsize("2cxi");

Dynamic (while specifying format string during istantiation), (*10)

require('vendor/autoload.php');
$struct = new \danog\PHP\StructClass("2cxi");
$pack = $struct->pack("ab", 44);
$unpack = $struct->unpack($pack);
var_dump($unpack);
$count = $struct->size;
$formatstring = $struct->format;

Static, (*11)

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, (*12)

The Versions

04/06 2018

dev-master

9999999-dev https://daniil.it/phpstruct

PHP implementation of python's struct module.

  Sources   Download

MIT

The Requires

  • php >=5.6.0

 

The Development Requires

by Avatar danog

string byte binary struct python float integer decimal unpack pack bytes

01/03 2017

dev-fast

dev-fast https://daniil.it/phpstruct

PHP implementation of python's struct module.

  Sources   Download

MIT

The Requires

  • php >=5.6.0

 

The Development Requires

by Avatar danog

string byte binary struct python float integer decimal unpack pack bytes

14/11 2016

1.2

1.2.0.0 https://daniil.it/phpstruct

PHP implementation of python's struct module.

  Sources   Download

MIT

The Requires

  • php >=5.6.0

 

The Development Requires

by Avatar danog

string byte binary struct python float integer decimal unpack pack bytes

14/11 2016

1.1.3

1.1.3.0 https://daniil.it/phpstruct

PHP implementation of python's struct module.

  Sources   Download

MIT

The Requires

  • php >=5.6.0

 

The Development Requires

by Avatar danog

string byte binary struct python float integer decimal unpack pack bytes

25/08 2016

1.1.2.1

1.1.2.1 https://daniil.it/phpstruct

PHP implementation of python's struct module.

  Sources   Download

MIT

The Requires

  • php >=5.6.0

 

The Development Requires

by Avatar danog

string byte binary struct python float integer decimal unpack pack bytes

14/08 2016

1.1.2

1.1.2.0 https://daniil.it/phpstruct

PHP implementation of python's struct module.

  Sources   Download

MIT

The Requires

  • php >=5.6.0

 

The Development Requires

by Avatar danog

byte struct python unpack pack bytes

14/08 2016

1.1.1

1.1.1.0 https://daniil.it/phpstruct

PHP implementation of python's struct module.

  Sources   Download

MIT

The Requires

  • php >=5.6.0

 

The Development Requires

by Avatar danog

byte struct python unpack pack bytes

29/07 2016

1.1

1.1.0.0 https://daniil.it/phpstruct

PHP implementation of python's struct module.

  Sources   Download

MIT

The Requires

  • php >=5.6.0

 

The Development Requires

by Avatar danog

byte struct python unpack pack bytes

28/07 2016

1.0

1.0.0.0 https://daniil.it/phpstruct

PHP implementation of python's struct module.

  Sources   Download

MIT

The Requires

  • php >=5.6.0

 

The Development Requires

by Avatar danog

byte struct python unpack pack bytes

15/07 2016

0.4.2

0.4.2.0 https://daniil.it/phpstruct

PHP implementation of python's struct module.

  Sources   Download

MIT

The Requires

  • php >=5.6.0

 

The Development Requires

by Avatar danog

byte struct python unpack pack bytes

15/07 2016

0.4.1

0.4.1.0 https://daniil.it/phpstruct

PHP implementation of python's struct module.

  Sources   Download

MIT

The Requires

  • php >=5.6.0

 

The Development Requires

by Avatar danog

byte struct python unpack pack bytes

13/07 2016

0.4

0.4.0.0 https://daniil.it/phpstruct

PHP implementation of python's struct module.

  Sources   Download

MIT

The Requires

 

by Avatar danog

byte struct python unpack pack bytes

12/07 2016

0.3.1

0.3.1.0 https://daniil.it/phpstruct

PHP implementation of python's struct module.

  Sources   Download

MIT

The Requires

 

by Avatar danog

byte struct python unpack pack bytes

12/07 2016

0.3

0.3.0.0 https://daniil.it/phpstruct

PHP implementation of python's struct module.

  Sources   Download

MIT

The Requires

  • php >=5.6.0

 

by Avatar danog

byte struct python unpack pack bytes

08/07 2016

0.2

0.2.0.0 https://daniil.it/phpstruct

PHP implementation of python's struct module.

  Sources   Download

MIT

The Requires

  • php >=5.6.0

 

by Avatar danog

byte struct python unpack pack bytes

04/07 2016

0.1

0.1.0.0 https://daniil.it/rightpack

PHP's pack() and unpack(), done the right way.

  Sources   Download

MIT

The Requires

  • php >=5.6.0

 

by Avatar danog

byte struct python unpack pack bytes