2010-05-05 15:50:07 +09:00
|
|
|
NAME
|
2010-09-06 14:19:31 +09:00
|
|
|
Data::MessagePack - MessagePack serialising/deserialising
|
2010-05-05 15:50:07 +09:00
|
|
|
|
|
|
|
SYNOPSIS
|
2010-09-19 15:15:31 +09:00
|
|
|
use Data::MessagePack;
|
|
|
|
|
2010-09-18 06:16:17 +09:00
|
|
|
my $packed = Data::MessagePack->pack($dat);
|
2010-05-05 15:50:07 +09:00
|
|
|
my $unpacked = Data::MessagePack->unpack($dat);
|
|
|
|
|
|
|
|
DESCRIPTION
|
2010-09-06 14:19:31 +09:00
|
|
|
This module converts Perl data structures to MessagePack and vice versa.
|
|
|
|
|
2010-09-10 20:42:40 +09:00
|
|
|
ABOUT MESSAGEPACK FORMAT
|
2010-09-06 14:19:31 +09:00
|
|
|
MessagePack is a binary-based efficient object serialization format. It
|
|
|
|
enables to exchange structured objects between many languages like JSON.
|
|
|
|
But unlike JSON, it is very fast and small.
|
2010-05-05 15:50:07 +09:00
|
|
|
|
2010-09-10 20:42:40 +09:00
|
|
|
ADVANTAGES
|
2010-09-18 06:16:17 +09:00
|
|
|
PORTABLE
|
|
|
|
The MessagePack format does not depend on language nor byte order.
|
2010-09-10 20:42:40 +09:00
|
|
|
|
2010-09-18 06:16:17 +09:00
|
|
|
SMALL IN SIZE
|
2010-09-10 20:42:40 +09:00
|
|
|
say length(JSON::XS::encode_json({a=>1, b=>2})); # => 13
|
|
|
|
say length(Storable::nfreeze({a=>1, b=>2})); # => 21
|
|
|
|
say length(Data::MessagePack->pack({a=>1, b=>2})); # => 7
|
|
|
|
|
2010-09-12 05:38:15 +09:00
|
|
|
The MessagePack format saves memory than JSON and Storable format.
|
2010-09-10 20:42:40 +09:00
|
|
|
|
|
|
|
STREAMING DESERIALIZER
|
|
|
|
MessagePack supports streaming deserializer. It is useful for
|
2010-09-18 06:16:17 +09:00
|
|
|
networking such as RPC. See Data::MessagePack::Unpacker for details.
|
2010-09-10 20:42:40 +09:00
|
|
|
|
2010-09-12 05:38:15 +09:00
|
|
|
If you want to get more information about the MessagePack format, please
|
2010-09-10 20:42:40 +09:00
|
|
|
visit to <http://msgpack.org/>.
|
|
|
|
|
2010-05-05 15:50:07 +09:00
|
|
|
METHODS
|
2010-09-10 21:27:38 +09:00
|
|
|
my $packed = Data::MessagePack->pack($data[, $max_depth]);
|
|
|
|
Pack the $data to messagepack format string.
|
|
|
|
|
2010-09-12 05:38:15 +09:00
|
|
|
This method throws an exception when the perl structure is nested
|
|
|
|
more than $max_depth levels(default: 512) in order to detect
|
|
|
|
circular references.
|
2010-09-10 21:27:38 +09:00
|
|
|
|
2010-09-12 05:38:15 +09:00
|
|
|
Data::MessagePack->pack() throws an exception when encountering
|
|
|
|
blessed object, because MessagePack is language-independent format.
|
2010-05-05 15:50:07 +09:00
|
|
|
|
|
|
|
my $unpacked = Data::MessagePack->unpack($msgpackstr);
|
2010-09-12 05:38:15 +09:00
|
|
|
unpack the $msgpackstr to a MessagePack format string.
|
2010-05-05 15:50:07 +09:00
|
|
|
|
|
|
|
Configuration Variables
|
|
|
|
$Data::MessagePack::PreferInteger
|
2010-09-18 06:16:17 +09:00
|
|
|
Packs a string as an integer, when it looks like an integer.
|
2010-05-05 15:50:07 +09:00
|
|
|
|
2010-09-10 20:42:40 +09:00
|
|
|
SPEED
|
2010-09-18 06:16:17 +09:00
|
|
|
This is a result of benchmark/serialize.pl and benchmark/deserialize.pl
|
2010-09-19 15:15:31 +09:00
|
|
|
on my SC440(Linux 2.6.32-23-server #37-Ubuntu SMP). (You should
|
|
|
|
benchmark them with your data if the speed matters, of course.)
|
2010-09-10 20:42:40 +09:00
|
|
|
|
|
|
|
-- serialize
|
|
|
|
JSON::XS: 2.3
|
2010-09-17 18:08:15 +09:00
|
|
|
Data::MessagePack: 0.24
|
2010-09-10 20:42:40 +09:00
|
|
|
Storable: 2.21
|
2010-09-17 18:08:15 +09:00
|
|
|
Benchmark: running json, mp, storable for at least 1 CPU seconds...
|
|
|
|
json: 1 wallclock secs ( 1.00 usr + 0.01 sys = 1.01 CPU) @ 141939.60/s (n=143359)
|
|
|
|
mp: 1 wallclock secs ( 1.06 usr + 0.00 sys = 1.06 CPU) @ 355500.94/s (n=376831)
|
|
|
|
storable: 1 wallclock secs ( 1.12 usr + 0.00 sys = 1.12 CPU) @ 38399.11/s (n=43007)
|
|
|
|
Rate storable json mp
|
|
|
|
storable 38399/s -- -73% -89%
|
|
|
|
json 141940/s 270% -- -60%
|
|
|
|
mp 355501/s 826% 150% --
|
2010-09-10 20:42:40 +09:00
|
|
|
|
|
|
|
-- deserialize
|
|
|
|
JSON::XS: 2.3
|
2010-09-17 18:08:15 +09:00
|
|
|
Data::MessagePack: 0.24
|
2010-09-10 20:42:40 +09:00
|
|
|
Storable: 2.21
|
2010-09-17 18:08:15 +09:00
|
|
|
Benchmark: running json, mp, storable for at least 1 CPU seconds...
|
|
|
|
json: 0 wallclock secs ( 1.05 usr + 0.00 sys = 1.05 CPU) @ 179442.86/s (n=188415)
|
|
|
|
mp: 0 wallclock secs ( 1.01 usr + 0.00 sys = 1.01 CPU) @ 212909.90/s (n=215039)
|
|
|
|
storable: 2 wallclock secs ( 1.14 usr + 0.00 sys = 1.14 CPU) @ 114974.56/s (n=131071)
|
|
|
|
Rate storable json mp
|
|
|
|
storable 114975/s -- -36% -46%
|
|
|
|
json 179443/s 56% -- -16%
|
|
|
|
mp 212910/s 85% 19% --
|
2010-09-10 20:42:40 +09:00
|
|
|
|
2010-09-18 15:05:22 +09:00
|
|
|
CAVEAT
|
|
|
|
Unpacking 64 bit integers
|
|
|
|
This module can unpack 64 bit integers even if your perl does not
|
|
|
|
support them (i.e. where "perl -V:ivsize" is 4), but you cannot
|
|
|
|
calculate these values unless you use "Math::BigInt".
|
|
|
|
|
2010-09-18 06:16:17 +09:00
|
|
|
TODO
|
|
|
|
Error handling
|
|
|
|
MessagePack cannot deal with complex scalars such as object
|
|
|
|
references, filehandles, and code references. We should report the
|
|
|
|
errors more kindly.
|
|
|
|
|
|
|
|
Streaming deserializer
|
|
|
|
The current implementation of the streaming deserializer does not
|
|
|
|
have internal buffers while some other bindings (such as Ruby
|
|
|
|
binding) does. This limitation will astonish those who try to unpack
|
|
|
|
byte streams with an arbitrary buffer size (e.g.
|
|
|
|
"while(read($socket, $buffer, $arbitrary_buffer_size)) { ... }"). We
|
|
|
|
should implement the internal buffer for the unpacker.
|
|
|
|
|
2010-10-06 12:27:04 +09:00
|
|
|
UTF8 mode
|
|
|
|
Data::MessagePack::Unpacker supports utf8 mode, which decodes
|
|
|
|
strings as UTF8-8. << Data::MessagePack->unpack >> should support
|
|
|
|
utf8 mode in a future.
|
|
|
|
|
2010-05-05 15:50:07 +09:00
|
|
|
AUTHORS
|
|
|
|
Tokuhiro Matsuno
|
|
|
|
|
2010-09-06 14:19:31 +09:00
|
|
|
Makamaka Hannyaharamitu
|
|
|
|
|
2010-09-18 06:16:17 +09:00
|
|
|
gfx
|
|
|
|
|
2010-05-05 15:50:07 +09:00
|
|
|
THANKS TO
|
|
|
|
Jun Kuriyama
|
|
|
|
|
2010-09-06 14:19:31 +09:00
|
|
|
Dan Kogai
|
|
|
|
|
|
|
|
FURUHASHI Sadayuki
|
|
|
|
|
2010-09-12 05:38:15 +09:00
|
|
|
hanekomu
|
|
|
|
|
2010-10-18 19:30:08 +09:00
|
|
|
Kazuho Oku
|
|
|
|
|
2010-05-05 15:50:07 +09:00
|
|
|
LICENSE
|
|
|
|
This library is free software; you can redistribute it and/or modify it
|
|
|
|
under the same terms as Perl itself.
|
|
|
|
|
|
|
|
SEE ALSO
|
2010-09-18 06:16:17 +09:00
|
|
|
<http://msgpack.org/> is the official web site for the MessagePack
|
|
|
|
format.
|
2010-05-05 15:50:07 +09:00
|
|
|
|
2010-09-19 15:15:31 +09:00
|
|
|
Data::MessagePack::Unpacker
|
|
|
|
|
|
|
|
AnyEvent::MPRPC
|
|
|
|
|