-
Notifications
You must be signed in to change notification settings - Fork 22
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
trying to unpack MessagePack from C failing with "extra bytes (length should be 145)" message #9
Comments
Can you send me a data file to reproduce? |
Sure, please, find it here: https://github.com/battleship-potemkin/test/blob/master/dump.cant_parse Here is the command to reproduce:
Please, let me know if any additional information required. |
Is dump.cant_parse valid ?
First data type is 0x87, this is fix map and it has 7 key & value pairs. You should use 'map 32' or 'map 16' for unpacking dump.cant_parse correctly. |
I guess it should, first of all, because Python's bindings unpack it very well. Regarding the elements - yes, we have (were packing) 7 keys and values there. |
dump.cant_parse has multiple data structures. They are following
Data::MessagePack::unpack can unpack 1 data structure, You should use Data::MessagePack::Stream such case. Sample code is following use strict;
use warnings;
use Data::MessagePack::Stream;
use Data::Dumper;
my $dump_file_name = shift or die "Usage: $0 message_packed_file";
my $dump_content = do {
local $/;
open my $fh, "<", $dump_file_name or die "Can't open $dump_file_name: $!";
<$fh>;
};
my $unpacker = Data::MessagePack::Stream->new;
$unpacker->feed($dump_content);
local $Data::Dumper::Terse = 1;
while ($unpacker->next) {
print Dumper($unpacker->data);
} And I get following output same as above
|
Thanks. Any way for the streams to be unpacked by using Pure Perl solution? Or, at least, to verify the structure without using C library? |
You can use Data::MessagePack::PP::Unpacker(Pure perl implementation of Data::MessagePack::Unpacker). Sample code is following. use strict;
use warnings;
use Data::MessagePack;
use Data::Dumper;
my $dump_file_name = shift or die "Usage: $0 message_packed_file";
my $dump_content = do {
local $/;
open my $fh, "<", $dump_file_name or die "Can't open $dump_file_name: $!";
<$fh>;
};
local $Data::Dumper::Terse = 1;
my $unpacker = Data::MessagePack::Unpacker->new;
my $limit = length $dump_content;
my $off = 0;
while (1) {
$off = $unpacker->execute($dump_content, $off);
print Dumper($unpacker->data);
$unpacker->reset;
last if $off >= $limit;
} output is
|
Lovely, it works now. Hope the module will keep working as it's the only Pure Perl unpack implementation available. Thanks syohex, tokuhirom for prompt reply, great help and scripts examples! |
Hi,
I'm trying to unpack MessagePack created from latest MessagePack C library, but it fails with the following error message:
Here is the test.pl script (working with Pure Perl implementation):
At the same time, Python's bindings work just fine.
Any clue?
Thanks in advance.
The text was updated successfully, but these errors were encountered: