Subject: | decoder fails to un-snappy a utf8 string |
Hi,
I'm sending to the Sereal decoder a valid encoded string, however its
utf8 flag is on. The snappy decompression fails.
I'm not sure it's a bug : maybe I'm not supposed to send the decoder
such string. Note : it fails at snappy uncompression.
Context : I'm encoding a structure, storing it in redis, and reading it
back. Redis happens to give me a perl string with utf8 internal flag
turned on. Sereal decoding then fails.
Workaround : detect if the string has the internal utf8 flag on. If yes,
encode the perl string into latin1. It then works fine.
So I have a workaround for this, but I thought maybe Sereal decodeer
(orthe snappy uncompressor) could check the utf8 flag and do appropriate
stuff if needed
attached a test case.
Subject: | test_sereal.pl |
#!/usr/bin/env perl
use Sereal::Encoder;
use Sereal::Decoder;
my $encoder = Sereal::Encoder->new({ snappy => 1, snappy_threshold => 0 });
my $decoder = Sereal::Decoder->new();
my $s1 = { foo => 'bar',
f111 => 'bar',
f1111 => 'bar',
f11111 => 'bar',
f111111 => 'bar',
f1111111 => 'bar',
f11111111 => 'bar',
f111111111 => 'bar',
f1111111111 => 'bar',
f11111111111 => 'bar',
f111111111111 => 'bar',
f1111111111111 => 'bar',
f11111111111111 => 'bar',
f111111111111111 => 'bar',
f1111111111111111 => 'bar',
f11111111111111111 => 'bar',
};
my $s2 = $encoder->encode($s1);
use Encode;
$s2 = encode("utf8", $s2);
$decoder->decode($s2);