What I am trying to achieve is the following :
There is a perl script that writes to a Redis DB the msgpack but without the utf8 encoding . I then need to get the value using node.js and unpack it. Also I need for the perl script to be able to get the value from db and unpack it
If I use in Perl
use strict;
use warnings;
use Data::MessagePack;
use Encode;
my $mp = Data::MessagePack->new();
my $packed = $mp->pack([qw(a b c d f)]);
print "packed:".$packed."\n";
my $encoded = Encode::encode_utf8($packed);
print "packed encoded using encode_utf8 :".$encoded."\n";
my $decoded = Encode::decode_utf8($encoded);
print "packed decoded using decode_utf8:".$decoded."\n";
my $unpacked = $mp->unpack($decoded);
print $unpacked."\n";
The output is:
packed:��a�b�c�d�f
packed encoded using encode_utf8 :¡a¡b¡c¡d¡f
packed decoded using decode_utf8:��a�b�c�d�f
Data::MessagePack->unpack: extra bytes at
/home/myname/workspace/test/test_msgpack.pl line 29.
Thus, I either don't convert anything in perl in utf8 before and just send it to db so that node.js does the rest , but it needs to convert the data also to a format that perl understands in order to unpack.
or
I don't do anything in node.js, but by just using any msgpack module that exist, I unpack the message for process and also pack and save it to db for Perl to fetch and unpack.
In the second option I have the problem stated above
Data::MessagePack->unpack: extra bytes at /home/myname/workspace/test/test_msgpack.pl line 29.
and in the first solution node.js does not understand the format of msgpack that perl saved to db