DR::Msgpuck - Perl bindings for msgpuck.
use DR::Msgpuck; my $blob = msgpack { a => 'b', c => 'd' }; my $object = msgunpack $blob; # all $object's string are utf8 my $object = msgunpack_utf8 $blob; # length of the first msgpack object in your buffer if (my $len = msgunpack_check $buffer) { my $o = msgunpack $buffer; substr $buffer, 0, $len, ''; ... }
msgpuck is a simple and efficient msgpack binary serialization library in a self-contained header file.
Msgpack protocol provides true/false values. They are unpacks to DR::Msgpuck::True and DR::Msgpuck::False instances.
true
false
If You have an object that can msgpack by itself, provide method TO_MSGPACK in it. Example:
TO_MSGPACK
package MyExt; sub new { my ($class, $value) = @_; bless \$value => ref($class) || $class; } sub TO_MSGPACK { my ($self) = @_; pack 'CC', 0xA1, substr $$self, 0, 1; } package main; use MyStr; my $object = { a => 'b', c => 'd', e => MyExt->new('f') }; my $blob = msgpack($object); ...
Packs perl object and returns msgpack's blob.
use DR::Msgpuck; my $blob = msgpack { a => 'b', c => 'd' };
Unpacks perl object (croaks if input buffer is invalid).
use DR::Msgpuck; my $object = msgunpack $blob;
Unpacks perl object. All strings will be encoded to utf-8.
utf-8
use DR::Msgpuck; # all $object's string are utf8 my $object = msgunpack_utf8 $blob;
Checks input buffer, returns length of the first msgpack object in the buffer.
use DR::Msgpuck; # length of the first msgpack object in your buffer if (my $len = msgunpack_check $buffer) { my $o = msgunpack $buffer; substr $buffer, 0, $len, ''; ... }
Packing benchmark Rate data-messagepack dr-msgpuck data-messagepack 211416/s -- -31% dr-msgpuck 306279/s 45% -- Unpacking benchmark Rate dr-msgpuck data-messagepack dr-msgpuck 191681/s -- -7% data-messagepack 206313/s 8% --
Dmitry E. Oboukhov, <unera@debian.org>
Copyright (C) 2016 by Dmitry E. Oboukhov
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.10.0 or, at your option, any later version of Perl 5 you may have available.
To install DR::Msgpuck, copy and paste the appropriate command in to your terminal.
cpanm
cpanm DR::Msgpuck
CPAN shell
perl -MCPAN -e shell install DR::Msgpuck
For more information on module installation, please visit the detailed CPAN module installation guide.