The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

MsgPack::Decoder - Decode data from a MessagePack stream

VERSION

version 1.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.

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 structures decoded so far.

    @data = $decoder->read_all($binary);

    # equivalent to
    
    $decoder->read(@binaries);
    @data = $decoder->all;

read_next( @binaries )

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;

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.