perl: fixed stream deserializer in pp.

This commit is contained in:
tokuhirom
2010-09-18 09:44:32 +09:00
parent 953aa95c64
commit 2c9966a0a3
5 changed files with 57 additions and 25 deletions

View File

@@ -37,7 +37,7 @@ for (my $i=0; $i<scalar(@dat); ) {
for (1..5) {
$up->execute("\xc0", 0); # nil
}
ok $up->is_finished;
is_deeply $up->data, [undef, undef, undef, undef, undef];
ok $up->is_finished, 'finished';
is_deeply $up->data, [undef, undef, undef, undef, undef], 'array, is_deeply';
}

View File

@@ -32,6 +32,7 @@ for my $mpac($mpac1, $mpac2) {
my $i = 0;
while($offset < length($mpac)) {
$offset = $mps->execute($mpac, $offset);
ok $mps->is_finished, "data[$i] : is_finished";
is_deeply $mps->data, $data[$i], "data[$i]";
$mps->reset;
$i++;

View File

@@ -27,12 +27,14 @@ foreach my $size(1 .. 16) {
open my $stream, '<:bytes :scalar', \$packed;
binmode $stream;
my $buff;
my $done = 0;
while( read($stream, $buff, $size) ) {
#note "buff: ", join " ", map { unpack 'H2', $_ } split //, $buff;
$up->execute($buff);
$done = $up->execute($buff);
}
ok $up->is_finished, 'is_finished';
is $done, length($packed);
ok $up->is_finished, "is_finished: $size";
my $data = $up->data;
is_deeply $data, $input;
}

View File

@@ -0,0 +1,23 @@
use strict;
use warnings;
use Data::MessagePack;
use Test::More;
use t::Util;
my @input = (
+[[]],
[[],[]],
[{"a" => 97},{"a" => 97}],
[{"a" => 97},{"a" => 97},{"a" => 97}],
);
plan tests => @input * 2;
for my $input (@input) {
my $packed = Data::MessagePack->pack($input);
my $up = Data::MessagePack::Unpacker->new();
$up->execute($packed, 0);
ok $up->is_finished, 'finished';
is_deeply($up->data, $input);
}