blob: 3ecf7445d7d0e9e8e8514aa2e8277c11b25125e2 (
plain)
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
40
41
42
43
|
use strict;
use warnings;
use Test::More;
use Data::MessagePack;
use Data::MessagePack::Stream;
my @input = ([1, 0, undef, "0"], [1, 1, undef, "1"]);
my $input_bytes;
my @input_boundaries;
for(my $i=0; $i<@input; $i++) {
$input_bytes .= Data::MessagePack->pack($input[$i]);
push @input_boundaries, length $input_bytes;
}
my $packet_size = 4;
for my $packet_size (1..1+length $input_bytes) {
note "Packet size: $packet_size";
my @input_packets = unpack("(a$packet_size)*", $input_bytes);
# note scalar @input_packets;
my $mps = Data::MessagePack::Stream->new;
my $pos = 0;
my $m = 0;
while (@input_packets) {
my $packet = shift @input_packets;
$pos += length $packet;
$mps->feed($packet);
while ($pos >= $input_boundaries[$m]) {
ok($mps->next, "$pos: complete message");
is_deeply($mps->data, $input[$m], "same message");
$m++;
last if $m >= @input_boundaries;
}
if (@input_packets && $pos < $input_boundaries[$m]) {
ok(! $mps->next, "$pos: incomplete message");
}
}
}
done_testing;
|