Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

* fixed utf8 packing in composites.

  • Loading branch information...
commit edcf3652110277c1cd7bcc1e08ad202c6ad4f23b 1 parent 2221f3a
Filipe Gonçalves authored
Showing with 21 additions and 9 deletions.
  1. +21 −9 lib/Cassandra/Composite.pm
View
30 lib/Cassandra/Composite.pm
@@ -26,7 +26,6 @@ sub composite {
my @args = @_;
@args = grep { defined($_) } @args;
- #print "Input -> ". Dumper \@args;
my $res = join "", map {
my $component = $_ || '';
my $eoc = "\x00";
@@ -34,29 +33,42 @@ sub composite {
( $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;
Please sign in to comment.
Something went wrong with that request. Please try again.