Permalink
Browse files

* fixed utf8 packing in composites.

  • Loading branch information...
Filipe Gonçalves
Filipe Gonçalves committed Mar 15, 2013
1 parent 2221f3a commit edcf3652110277c1cd7bcc1e08ad202c6ad4f23b
Showing with 21 additions and 9 deletions.
  1. +21 −9 lib/Cassandra/Composite.pm
View
@@ -26,37 +26,49 @@ sub composite {
my @args = @_;
@args = grep { defined($_) } @args;
- #print "Input -> ". Dumper \@args;
my $res = join "", map {
my $component = $_ || '';
my $eoc = "\x00";
if (UNIVERSAL::isa( $_, 'ARRAY' ) ) {
( $component, my $last, my $inclusive ) = @{$component};
$eoc = !$inclusive ^ !$last ? "\xff" : "\x01";
}
+ use bytes;
pack( "n", length($component) ) . $component . $eoc;
} @args;
- #print "Output -> ". $res;
return $res;
}
sub composite_to_array {
+ use bytes;
my $name = shift;
+ my @ret = ();
- #print "Input -> ".Dumper $name;
my $size = length($name);
- my @a;
+
+ if (! $size) {
+ return \@ret;
+ }
+
+ my @bytes = split //, $name;
my $len = 0;
while ( $len < $size ) {
- my $off = unpack( 'n', substr $name, $len, $len + 2 );
- push @a, substr $name, $len + 2, $off;
+ my $off = unpack( 'n', $bytes[$len].$bytes[$len+1] );
+
+ my $comp = '';
+ for(1..$off) {
+ my $i = $_;
+ $comp .= $bytes[$len+1+$i];
+ }
+
+ push @ret, $comp;
$len += $off + 3;
- };
+ }
- #print "Output ->". Dumper \@a;
- return \@a;
+
+ return \@ret;
}
1;

0 comments on commit edcf365

Please sign in to comment.