2017 © Pedro Peláez
 

library msgpack

Msgpack implementation for PHP. It's like JSON. But fast and small.

image

hannesvdvreken/msgpack

Msgpack implementation for PHP. It's like JSON. But fast and small.

  • Friday, January 16, 2015
  • by hannesvdvreken
  • Repository
  • 3 Watchers
  • 9 Stars
  • 2,646 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 1 Forks
  • 1 Open issues
  • 1 Versions
  • 0 % Grown

The README.md

Msgpack implementation for Modern PHP

Build Status License, (*1)

What is Msgpack?

If you ever wished to use JSON for convenience (storing an image with metadata) but could not for technical reasons (encoding, size, speed...), MessagePack is a perfect replacement., (*2)

MessagePack is an efficient binary serialization format. It lets you exchange data among multiple languages like JSON. But it's faster and smaller. Small integers are encoded into a single byte, and typical short strings require only one extra byte in addition to the strings themselves., (*3)

For more information on Msgpack: msgpack.org, (*4)

Usage

There are 2 main classes with each a single method to use:, (*5)

$encoder = new Msgpack\Encoder();
$string = $encoder->encode($data);

$decoder = new Msgpack\Decoder();
$data = $decoder->decode($string);

Or if you prefer, you can also call the static methods with the exact same interface:, (*6)

$string = Msgpack\Encoder::encode($data);

$decoder = Msgpack\Decoder::decode($string);

This is to allow you to inject the encoder and decoder into your classes so you can mock them out., (*7)

Some messages or encoded string throw exceptions because Msgpack has its limitations:, (*8)

try {
    $string = $encoder->encode($data);
} catch (Msgpack\UnencodeableException $unencex) {
    //
}
try {
    $string = $decoder->decode($string);
} catch (Msgpack\UndecodeableException $undecex) {
    //
}

Testing

Run tests with composer test., (*9)

Other packages

This is not the first packagist package on msgpack, but it is the first that is not an RPC client for the Msgpack cli tool. This package doesn't require any external non-php libraries to be installed. The default Msgpack library is a PECL library, so not so interesting to install., (*10)

License

MIT, (*11)

The Versions

16/01 2015

dev-master

9999999-dev

Msgpack implementation for PHP. It's like JSON. But fast and small.

  Sources   Download

MIT

The Requires

  • php ~5.3

 

The Development Requires

json fast msgpack small