NAME
MsgPack::Decoder - Decode data from a MessagePack stream
VERSION
version 0.0.1
SYNOPSIS
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' ]
DESCRIPTION
MsgPack::Decoder
objects take in the raw binary representation of one or more MessagePack data structures, and convert it back into their Perl representations.
CURRENTLY SUPPORTED MESSAGEPACK TYPES
I'm implementing the different messagepack types as I go along. So far, the current types are supported:
- Boolean
- PositiveFixInt
- NegativeFixInt
- FixStr
- Str8
- FixArray
- Nil
- FixMap
- FixExt1
METHODS
This class consumes MooseX::Role::Loggable, and inherits all of its methods.
read( @binary_values )
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.
has_buffer
Returns the number of decoded structures currently waiting in the buffer.
next
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:
$decoder->read( $binary );
# NO! $next could be 'undef'
while( my $next = $decoder->next ) {
do_stuff( $next );
}
all
Returns (and flush from the buffer) all the currently available structures.
read_all( @binaries )
Reads the provided binary data and returns all structured decoded so far.
@data = $decoder->read_all($binary);
# equivalent to
$decoder->read(@binaries);
@data = $decoder->all;
AUTHOR
Yanick Champoux <yanick@cpan.org>
COPYRIGHT AND LICENSE
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.