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

0 views
Skip to first unread message

codesite...@google.com

unread,
Jul 30, 2008, 5:42:13 PM7/30/08
to protobuf-p...@googlegroups.com
Author: br...@danga.com
Date: Wed Jul 30 14:42:08 2008
New Revision: 152

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

Log:
int32

Modified: trunk/perl/lib/Protobuf/Decoder.pm
==============================================================================
--- trunk/perl/lib/Protobuf/Decoder.pm (original)
+++ trunk/perl/lib/Protobuf/Decoder.pm Wed Jul 30 14:42:08 2008
@@ -91,9 +91,23 @@
return $int;
}

+my $sign_bit_64 = Math::BigInt->new("0x8000000000000000");
+
sub decode_field_int32 {
my ($self, $int) = @_;
- return $int;
+ if (UNIVERSAL::isa($int, "Math::BigInt")) {
+ if ($int & $sign_bit_64) {
+ # TODO(bradfitz): pairs of bnot works too. benchmark
which is faster.
+ $int->bneg;
+ $int &= Math::BigInt->new("0xffffffffffffffff");
+ $int->bneg;
+ $int = $int->numify;
+ return $int;
+ }
+ # shouldn't get here, though?
+ return $int->numify;
+ }
+ return unpack("l", pack("L", int($int)));
}

sub decode_field_fixed32 {

Reply all
Reply to author
Forward
0 new messages