NAME
DR::Msgpuck - Perl bindings for msgpuck.
SYNOPSIS
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, '';
...
}
DESCRIPTION
msgpuck is a simple and efficient msgpack binary serialization library in a self-contained header file.
Boolean
Msgpack protocol provides true
/false
values. They are unpacks to DR::Msgpuck::True and DR::Msgpuck::False instances.
Injections
If You have an object that can msgpack by itself, provide method TO_MSGPACK
in it. Example:
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);
...
METHODS
msgpack
Packs perl object and returns msgpack's blob.
example
use DR::Msgpuck;
my $blob = msgpack { a => 'b', c => 'd' };
msgunpack
Unpacks perl object (croaks if input buffer is invalid).
example
use DR::Msgpuck;
my $object = msgunpack $blob;
msgunpack_utf8
Unpacks perl object. All strings will be encoded to utf-8
.
example
use DR::Msgpuck;
# all $object's string are utf8
my $object = msgunpack_utf8 $blob;
msgunpack_check
Checks input buffer, returns length of the first msgpack object in the buffer.
example
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, '';
...
}
BENCHMARKS
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% --
AUTHOR
Dmitry E. Oboukhov, <unera@debian.org>
COPYRIGHT AND LICENSE
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.