[protobuf-perl commit] r155 - in trunk/perl: . lib/Protobuf t

0 views
Skip to first unread message

codesite...@google.com

unread,
Jul 31, 2008, 12:32:16 PM7/31/08
to protobuf-p...@googlegroups.com
Author: br...@danga.com
Date: Thu Jul 31 09:32:05 2008
New Revision: 155

Modified:
trunk/perl/TODO
trunk/perl/lib/Protobuf/Decoder.pm
trunk/perl/t/wire-numbers.t

Log:
positive enums

Modified: trunk/perl/TODO
==============================================================================
--- trunk/perl/TODO (original)
+++ trunk/perl/TODO Thu Jul 31 09:32:05 2008
@@ -3,6 +3,7 @@
make unittest.proto work
-- extensions
-- imports ("use" the perl_outer_package of the imported package)
+ -- negative enums are broken. see t/wire-numbers.t
-- use Math::BigInt on large default values. currently:
default_value => 18446744073709551615,
# Tried to use 'ProtobufTestBasic'.

Modified: trunk/perl/lib/Protobuf/Decoder.pm
==============================================================================
--- trunk/perl/lib/Protobuf/Decoder.pm (original)
+++ trunk/perl/lib/Protobuf/Decoder.pm Thu Jul 31 09:32:05 2008
@@ -81,15 +81,19 @@
return $string;
}

-sub decode_field_uint32 {
- my ($self, $int) = @_;
- return $int;
+sub _decode_field_no_xform_needed {
+ return $_[1];
}

-sub decode_field_uint64 {
- my ($self, $int) = @_;
- return $int;
-}
+# The wire decoder has already converted these varints into
+# unsigned integers, so we don't need to do anything:
+*decode_field_uint32 = \&_decode_field_no_xform_needed;
+*decode_field_uint64 = \&_decode_field_no_xform_needed;
+
+# TODO(bradfitz): This is a lie: Enums can be negative, according to
+# the Python impl at least. So we need to fix this in the future.
+# But I don't need negative enums for Perl App Engine at present.
+*decode_field_enum = \&_decode_field_no_xform_needed;

my $sign_bit_64 = Math::BigInt->new("0x8000000000000000");


Modified: trunk/perl/t/wire-numbers.t
==============================================================================
--- trunk/perl/t/wire-numbers.t (original)
+++ trunk/perl/t/wire-numbers.t Thu Jul 31 09:32:05 2008
@@ -91,9 +91,18 @@

['float', 1.0/3.0, "]"."\xab\xaa\xaa>"],
['double', 1.0/3.0, "a"."UUUUUU\xd5?"],
+
+ ['nested_enum', 2, "\xa8\x01\x02"],
+
+ # negative enums are allowed, I guess. Python allows them. Not
zigzag, though.
+ # TODO(bradfitz): include this failing test:
+ # ['nested_enum', -2, "\xa8\x01\xfe\xff\xff\xff\xff\xff\xff\xff\xff\x01"],
);

foreach my $t (@tests) {
+ # Note that $type is really just the field name, which is almost
+ # always the actual type in unittest.proto. It's not for
+ # 'nested_enum' though.
my ($type, $num, $expected_encoded) = @$t;
next if $ENV{TEST_TYPE} && $type ne $ENV{TEST_TYPE};

Reply all
Reply to author
Forward
0 new messages