File: 11_stream_unpack3.t

package info (click to toggle)
libdata-messagepack-perl 1.02-3
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 1,060 kB
  • sloc: ansic: 5,697; perl: 1,123; makefile: 10
file content (39 lines) | stat: -rw-r--r-- 717 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
use strict;
use warnings;
use Test::More;
use Data::MessagePack;

my @data = ( [ 1, 2, 3 ], [ 4, 5, 6 ] );

# serialize
my $buffer = '';
for my $d (@data) {
    $buffer .= Data::MessagePack->pack($d);
}

# deserialize
my $cb = sub {
    my ($data) = @_;

    my $d = shift @data;
    is_deeply $data, $d;
};
my $unpacker = Data::MessagePack::Unpacker->new();
my $nread = 0;
while (1) {
    $nread = $unpacker->execute( $buffer, $nread );
    if ( $unpacker->is_finished ) {
        my $ret = $unpacker->data;
        $cb->( $ret );
        $unpacker->reset;

        $buffer = substr( $buffer, $nread );
        $nread = 0;
        next if length($buffer) != 0;
    }
    last;
}
is scalar(@data), 0;

done_testing;