MsgPack::Decoder - Decode data from a MessagePack stream
version 1.0.1
use MsgPack::Decoder; use MsgPack::Encoder; use Data::Printer; my $decoder = MsgPack::Decoder->new; my $msgpack_binary = MsgPack::Encoder->new(struct => [ "hello world" ] )->encoded; $decoder->read( $msgpack_binary ); my $struct = $decode->next; p $struct; # prints [ 'hello world' ]
MsgPack::Decoder objects take in the raw binary representation of one or more MessagePack data structures, and convert it back into their Perl representations.
MsgPack::Decoder
This class consumes MooseX::Role::Loggable, and inherits all of its methods.
Reads in the raw binary to convert. The binary can be only a partial piece of the encoded structures. If so, all structures that can be decoded will be made available in the buffer, while the potentially last unterminated structure will remain "in flight".
Returns how many structures were decoded.
Returns the number of decoded structures currently waiting in the buffer.
Returns the next structure from the buffer.
$decoder->read( $binary ); while( $decoder->has_buffer ) { my $next = $decoder->next; do_stuff( $next ); }
Note that the returned structure could be undef, so don't do:
undef
$decoder->read( $binary ); # NO! $next could be 'undef' while( my $next = $decoder->next ) { do_stuff( $next ); }
Returns (and flush from the buffer) all the currently available structures.
Reads the provided binary data and returns all structures decoded so far.
@data = $decoder->read_all($binary); # equivalent to $decoder->read(@binaries); @data = $decoder->all;
Reads the provided binary data and returns the next structure decoded so far. If there is no data in the buffer, dies.
$data = $decoder->read_next($binary); # roughly equivalent to $decoder->read(@binaries); $data = $decoder->next or die;
Yanick Champoux <yanick@cpan.org>
This software is copyright (c) 2015 by Yanick Champoux.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
To install MsgPack::RPC, copy and paste the appropriate command in to your terminal.
cpanm
cpanm MsgPack::RPC
CPAN shell
perl -MCPAN -e shell install MsgPack::RPC
For more information on module installation, please visit the detailed CPAN module installation guide.