[protobuf-perl commit] r150 - trunk/perl/lib/Protobuf

0 views
Skip to first unread message

codesite...@google.com

unread,
Jul 30, 2008, 5:00:53 PM7/30/08
to protobuf-p...@googlegroups.com
Author: br...@danga.com
Date: Wed Jul 30 14:00:35 2008
New Revision: 150

Modified:
trunk/perl/lib/Protobuf/Decoder.pm

Log:
sfixed64

Modified: trunk/perl/lib/Protobuf/Decoder.pm
==============================================================================
--- trunk/perl/lib/Protobuf/Decoder.pm (original)
+++ trunk/perl/lib/Protobuf/Decoder.pm Wed Jul 30 14:00:35 2008
@@ -24,6 +24,20 @@
return unpack("l", $v);
}

+sub decode_field_sfixed64 {
+ my ($class, $v) = @_;
+ die "assert: length not 8 bytes" unless length($v) == 8;
+ my $is_neg = vec($v, 63, 1);
+ # TODO(bradfitz): sick of the pack manpage... this works for now.
+ my $hex = join('', sprintf("%02x"x8, reverse unpack("C16", $v)));
+ my $int = Math::BigInt->new("0x$hex");
+ if ($is_neg) {
+ $int->bnot;
+ $int->binc;
+ }
+ return $int;
+}
+
sub decode_field_float {
my ($class, $v) = @_;
die 'assert: should be 8 bytes' unless length($v) == 4;

Reply all
Reply to author
Forward
0 new messages