[protobuf-perl commit] r164 - in trunk: perl perl/lib/Protobuf perl/lib/Protobuf/Meta perl/t perl/t/autogen perl/t/autog...

2 views
Skip to first unread message

codesite...@google.com

unread,
Sep 2, 2008, 4:43:20 PM9/2/08
to protobuf-p...@googlegroups.com
Author: jeremywleader
Date: Tue Sep 2 13:42:04 2008
New Revision: 164

Modified:
trunk/perl/TODO
trunk/perl/lib/Protobuf/Decoder.pm
trunk/perl/lib/Protobuf/Encoder.pm
trunk/perl/lib/Protobuf/Meta/Message.pm
trunk/perl/lib/Protobuf/Types.pm
trunk/perl/t/autogen/AppEngine/Service/MemcacheProto.pm
trunk/perl/t/autogen/ProtobufTestBasic.pm
trunk/perl/t/data/memcache_service.proto
trunk/perl/t/decoder.t
trunk/perl/t/encoder.t
trunk/perl/t/lib/Test/Protobuf.pm
trunk/perl/t/wire-format.t
trunk/perl/t/wire-numbers.t
trunk/protobuf/src/google/protobuf/compiler/perl/perl_generator.cc

Log:
Make it work in 64-bit Perl. See http://codereview.appspot.com/2832


Modified: trunk/perl/TODO
==============================================================================
--- trunk/perl/TODO (original)
+++ trunk/perl/TODO Tue Sep 2 13:42:04 2008
@@ -4,15 +4,6 @@
-- 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'.
- # Error: Validation failed for 'Protobuf::Types::PositiveInt'
failed with
- # value 1.84467440737096e+19 at
lib/Protobuf/Attribute/Field/Scalar.pm line 42.
-
-
-- default_value => 18446744073709551615,
-+ default_value => Math::BigInt->new("18446744073709551615"),

This noise:
Constant subroutine ProtobufTestBasic::TestAllTypes::NestedEnum::FOO
redefined at lib/Protobuf/Attribute/Field.pm line 44.

Modified: trunk/perl/lib/Protobuf/Decoder.pm
==============================================================================
--- trunk/perl/lib/Protobuf/Decoder.pm (original)
+++ trunk/perl/lib/Protobuf/Decoder.pm Tue Sep 2 13:42:04 2008
@@ -23,13 +23,24 @@
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;
+ my $int;
+ if (HAS_QUADS) {
+ if (QUAD_ENDIANESS == QUAD_LEB) {
+ $int = unpack("q", $v);
+ } elsif (QUAD_ENDIANESS == QUAD_BEB) {
+ $int = unpack("q", reverse $v);
+ } else {
+ die "endianess unknown";
+ }
+ } else {
+ # TODO(bradfitz): sick of the pack manpage... this works for now.
+ my $hex = sprintf("%02x"x8, reverse unpack("C16", $v));
+ $int = Math::BigInt->new("0x$hex");
+ my $is_neg = vec($v, 63, 1);
+ if ($is_neg) {
+ $int->bnot;
+ $int->binc;
+ }
}
return $int;
}
@@ -37,10 +48,20 @@
sub decode_field_fixed64 {
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");
+ my $int;
+ if (HAS_QUADS) {
+ if (QUAD_ENDIANESS == QUAD_LEB) {
+ $int = unpack("Q", $v);
+ } elsif (QUAD_ENDIANESS == QUAD_BEB) {
+ $int = unpack("Q", reverse $v);
+ } else {
+ die "endianess unknown";
+ }
+ } else {
+ # TODO(bradfitz): sick of the pack manpage... this works for now.
+ my $hex = sprintf("%02x"x8, reverse unpack("C16", $v));
+ $int = Math::BigInt->new("0x$hex");
+ }
return $int;
}

@@ -95,15 +116,19 @@
# 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");
+my $sign_bit_64 = BI("0x8000000000000000");
+my $all_64_bits = BI("0xffffffffffffffff");

sub decode_field_int64 {
my ($self, $int) = @_;
if (UNIVERSAL::isa($int, "Math::BigInt") && ($int & $sign_bit_64)) {
# TODO(bradfitz): pairs of bnot works too. benchmark which is
faster.
$int->bneg;
- $int &= Math::BigInt->new("0xffffffffffffffff");
+ $int &= $all_64_bits;
$int->bneg;
+ } elsif (HAS_QUADS && ($int & $sign_bit_64)) {
+ $int = (~$int + 1) & $all_64_bits;
+ $int = -$int;
}
return $int;
}
@@ -114,13 +139,17 @@
if ($int & $sign_bit_64) {
# TODO(bradfitz): pairs of bnot works too. benchmark which is
faster.
$int->bneg;
- $int &= Math::BigInt->new("0xffffffffffffffff");
+ $int &= $all_64_bits;
$int->bneg;
$int = $int->numify;
return $int;
}
# shouldn't get here, though?
return $int->numify;
+ } elsif (HAS_QUADS && ($int & $sign_bit_64)) {
+ $int = (~$int + 1) & $all_64_bits;
+ $int = -$int;
+ return $int;
}
# If it was negative at all, it would've been a negative 64-bit
# number (10 byte varint), so we know this is not a bigint and not

Modified: trunk/perl/lib/Protobuf/Encoder.pm
==============================================================================
--- trunk/perl/lib/Protobuf/Encoder.pm (original)
+++ trunk/perl/lib/Protobuf/Encoder.pm Tue Sep 2 13:42:04 2008
@@ -28,6 +28,8 @@
$self->encode_varint( ( $field << 3 ) | $wire );
}

+my $all_64_bits = BI("0xffffffffffffffff");
+
sub encode_varint {
my ( $self, $int ) = @_;

@@ -39,7 +41,7 @@
# unset the sign bit
if ( $int < 0 ) {
$neg = 1;
- $int = Math::BigInt->new("0xffffffffffffffff") & $int;
+ $int = $all_64_bits & $int;
}

while ( $int > 127 ) {
@@ -171,14 +173,24 @@
# but hopefully somebody (me?) improves this later.
sub encode_field_sfixed64 {
my ( $self, $field, $num ) = @_;
- $num = Math::BigInt->new($num) unless
UNIVERSAL::isa($num, "Math::BigInt");
- my $hex = $num->as_hex;
- $hex =~ s/^\-//;
- # pad it, skipping leading 0x
- $hex = "0"x(18-length($hex)) . substr($hex, 2);
my $buf;
- for (0..7) {
- $buf .= chr(hex(substr($hex, 2*(7-$_), 2)));
+ if (HAS_QUADS) {
+ if (QUAD_ENDIANESS == QUAD_LEB) {
+ $buf = pack("q", $num);
+ } elsif (QUAD_ENDIANESS == QUAD_BEB) {
+ $buf = reverse pack("q", $num);
+ } else {
+ die "endianess unknown";
+ }
+ } else {
+ $num = Math::BigInt->new($num) unless
UNIVERSAL::isa($num, "Math::BigInt");
+ my $hex = $num->as_hex;
+ $hex =~ s/^\-//;
+ # pad it, skipping leading 0x
+ $hex = "0"x(18-length($hex)) . substr($hex, 2);
+ for (0..7) {
+ $buf .= chr(hex(substr($hex, 2*(7-$_), 2)));
+ }
}
$self->encode_wire_fixed64($field, $buf);
}

Modified: trunk/perl/lib/Protobuf/Meta/Message.pm
==============================================================================
--- trunk/perl/lib/Protobuf/Meta/Message.pm (original)
+++ trunk/perl/lib/Protobuf/Meta/Message.pm Tue Sep 2 13:42:04 2008
@@ -54,7 +54,7 @@
methods => { $metaclass->generate_default_methods(%args,
class => $name) },
);

- # TODO(bradfitz): do this earlier, and pass is to
+ # TODO(bradfitz): do this earlier, and pass it to
# generate_default_methods, so it can be captured by all the
# methods, so they don't have to do it themselves?
my $meta = Class::MOP::Class->initialize($name);

Modified: trunk/perl/lib/Protobuf/Types.pm
==============================================================================
--- trunk/perl/lib/Protobuf/Types.pm (original)
+++ trunk/perl/lib/Protobuf/Types.pm Tue Sep 2 13:42:04 2008
@@ -23,7 +23,7 @@

our @EXPORT = qw(
type_to_wire type_name wire_type_name type_constraint
- HAS_QUADS SQUAD_TYPE UQUAD_TYPE QUAD_ENDIANESS QUAD_LEB QUAD_BEB
+ HAS_QUADS SQUAD_TYPE UQUAD_TYPE QUAD_ENDIANESS QUAD_LEB QUAD_BEB BI
); # and some exports

use constant ();
@@ -158,6 +158,23 @@
sub type_constraint {
$type_constraint{type_name($_[0])};
}
+
+# Helper function for initializing ints with strings
+sub BI {
+ my $v = $_[0];
+ if (HAS_QUADS) {
+ return 0+$v if $v =~ /^-?\d+$/;
+ if ($v =~ /^0x[0-9a-fA-F]{1,16}/) {
+ my ($high, $low) = unpack("NN", pack("H*", substr($v,2)));
+ return $high << 32 | $low;
+ } else {
+ die "unknown number format: $v";
+ }
+ } else {
+ return Math::BigInt->new($v);
+ }
+}
+

__PACKAGE__


Modified: trunk/perl/t/autogen/AppEngine/Service/MemcacheProto.pm
==============================================================================
--- trunk/perl/t/autogen/AppEngine/Service/MemcacheProto.pm (original)
+++ trunk/perl/t/autogen/AppEngine/Service/MemcacheProto.pm Tue Sep 2
13:42:04 2008
@@ -5,15 +5,16 @@
use warnings;
use 5.6.1;
use Protobuf;
+use Protobuf::Types;

package AppEngine::Service::MemcacheProto;

package AppEngine::Service;

+
use constant TRUE => 1;
use constant FALSE => 0;
## Top-level enums:
-
## Top-level extensions:

## All nested enums:
@@ -344,7 +345,7 @@
Protobuf::FieldDescriptor->new(
name => 'delta', index => 1, number => 2,
type => 4, cpp_type => 4, label => 1,
- default_value => 1,
+ default_value => Protobuf::Types::BI("1"),
message_type => undef, enum_type => undef, containing_type => undef,
is_extension => FALSE, extension_scope => undef),
Protobuf::FieldDescriptor->new(
@@ -373,7 +374,7 @@
Protobuf::FieldDescriptor->new(
name => 'new_value', index => 0, number => 1,
type => 4, cpp_type => 4, label => 1,
- default_value => 0,
+ default_value => Protobuf::Types::BI("0"),
message_type => undef, enum_type => undef, containing_type => undef,
is_extension => FALSE, extension_scope => undef),
],
@@ -443,31 +444,31 @@
Protobuf::FieldDescriptor->new(
name => 'hits', index => 0, number => 1,
type => 4, cpp_type => 4, label => 2,
- default_value => 0,
+ default_value => Protobuf::Types::BI("0"),
message_type => undef, enum_type => undef, containing_type => undef,
is_extension => FALSE, extension_scope => undef),
Protobuf::FieldDescriptor->new(
name => 'misses', index => 1, number => 2,
type => 4, cpp_type => 4, label => 2,
- default_value => 0,
+ default_value => Protobuf::Types::BI("0"),
message_type => undef, enum_type => undef, containing_type => undef,
is_extension => FALSE, extension_scope => undef),
Protobuf::FieldDescriptor->new(
name => 'byte_hits', index => 2, number => 3,
type => 4, cpp_type => 4, label => 2,
- default_value => 0,
+ default_value => Protobuf::Types::BI("0"),
message_type => undef, enum_type => undef, containing_type => undef,
is_extension => FALSE, extension_scope => undef),
Protobuf::FieldDescriptor->new(
name => 'items', index => 3, number => 4,
type => 4, cpp_type => 4, label => 2,
- default_value => 0,
+ default_value => Protobuf::Types::BI("0"),
message_type => undef, enum_type => undef, containing_type => undef,
is_extension => FALSE, extension_scope => undef),
Protobuf::FieldDescriptor->new(
name => 'bytes', index => 4, number => 5,
type => 4, cpp_type => 4, label => 2,
- default_value => 0,
+ default_value => Protobuf::Types::BI("0"),
message_type => undef, enum_type => undef, containing_type => undef,
is_extension => FALSE, extension_scope => undef),
Protobuf::FieldDescriptor->new(

Modified: trunk/perl/t/autogen/ProtobufTestBasic.pm
==============================================================================
--- trunk/perl/t/autogen/ProtobufTestBasic.pm (original)
+++ trunk/perl/t/autogen/ProtobufTestBasic.pm Tue Sep 2 13:42:04 2008
@@ -5,7 +5,7 @@
use warnings;
use 5.6.1;
use Protobuf;
-package ProtobufTestBasic;
+use Protobuf::Types;

package ProtobufTestBasic;

@@ -64,7 +64,6 @@
$_TESTSPARSEENUM->values->[6]->set_type($_TESTSPARSEENUM);


-
## Top-level extensions:

## All nested enums:
@@ -159,7 +158,7 @@
Protobuf::FieldDescriptor->new(
name => 'optional_int64', index => 1, number => 2,
type => 3, cpp_type => 2, label => 1,
- default_value => 0,
+ default_value => Protobuf::Types::BI("0"),
message_type => undef, enum_type => undef, containing_type => undef,
is_extension => FALSE, extension_scope => undef),
Protobuf::FieldDescriptor->new(
@@ -171,7 +170,7 @@
Protobuf::FieldDescriptor->new(
name => 'optional_uint64', index => 3, number => 4,
type => 4, cpp_type => 4, label => 1,
- default_value => 0,
+ default_value => Protobuf::Types::BI("0"),
message_type => undef, enum_type => undef, containing_type => undef,
is_extension => FALSE, extension_scope => undef),
Protobuf::FieldDescriptor->new(
@@ -183,7 +182,7 @@
Protobuf::FieldDescriptor->new(
name => 'optional_sint64', index => 5, number => 6,
type => 18, cpp_type => 2, label => 1,
- default_value => 0,
+ default_value => Protobuf::Types::BI("0"),
message_type => undef, enum_type => undef, containing_type => undef,
is_extension => FALSE, extension_scope => undef),
Protobuf::FieldDescriptor->new(
@@ -195,7 +194,7 @@
Protobuf::FieldDescriptor->new(
name => 'optional_fixed64', index => 7, number => 8,
type => 6, cpp_type => 4, label => 1,
- default_value => 0,
+ default_value => Protobuf::Types::BI("0"),
message_type => undef, enum_type => undef, containing_type => undef,
is_extension => FALSE, extension_scope => undef),
Protobuf::FieldDescriptor->new(
@@ -207,7 +206,7 @@
Protobuf::FieldDescriptor->new(
name => 'optional_sfixed64', index => 9, number => 10,
type => 16, cpp_type => 2, label => 1,
- default_value => 0,
+ default_value => Protobuf::Types::BI("0"),
message_type => undef, enum_type => undef, containing_type => undef,
is_extension => FALSE, extension_scope => undef),
Protobuf::FieldDescriptor->new(
@@ -423,7 +422,7 @@
Protobuf::FieldDescriptor->new(
name => 'default_int64', index => 45, number => 62,
type => 3, cpp_type => 2, label => 1,
- default_value => 42,
+ default_value => Protobuf::Types::BI("42"),
message_type => undef, enum_type => undef, containing_type => undef,
is_extension => FALSE, extension_scope => undef),
Protobuf::FieldDescriptor->new(
@@ -435,7 +434,7 @@
Protobuf::FieldDescriptor->new(
name => 'default_uint64', index => 47, number => 64,
type => 4, cpp_type => 4, label => 1,
- default_value => 44,
+ default_value => Protobuf::Types::BI("44"),
message_type => undef, enum_type => undef, containing_type => undef,
is_extension => FALSE, extension_scope => undef),
Protobuf::FieldDescriptor->new(
@@ -447,7 +446,7 @@
Protobuf::FieldDescriptor->new(
name => 'default_sint64', index => 49, number => 66,
type => 18, cpp_type => 2, label => 1,
- default_value => 46,
+ default_value => Protobuf::Types::BI("46"),
message_type => undef, enum_type => undef, containing_type => undef,
is_extension => FALSE, extension_scope => undef),
Protobuf::FieldDescriptor->new(
@@ -459,7 +458,7 @@
Protobuf::FieldDescriptor->new(
name => 'default_fixed64', index => 51, number => 68,
type => 6, cpp_type => 4, label => 1,
- default_value => 48,
+ default_value => Protobuf::Types::BI("48"),
message_type => undef, enum_type => undef, containing_type => undef,
is_extension => FALSE, extension_scope => undef),
Protobuf::FieldDescriptor->new(
@@ -471,7 +470,7 @@
Protobuf::FieldDescriptor->new(
name => 'default_sfixed64', index => 53, number => 70,
type => 16, cpp_type => 2, label => 1,
- default_value => -50,
+ default_value => Protobuf::Types::BI("-50"),
message_type => undef, enum_type => undef, containing_type => undef,
is_extension => FALSE, extension_scope => undef),
Protobuf::FieldDescriptor->new(
@@ -1181,7 +1180,7 @@
Protobuf::FieldDescriptor->new(
name => 'my_int', index => 1, number => 1,
type => 3, cpp_type => 2, label => 1,
- default_value => 0,
+ default_value => Protobuf::Types::BI("0"),
message_type => undef, enum_type => undef, containing_type => undef,
is_extension => FALSE, extension_scope => undef),
Protobuf::FieldDescriptor->new(
@@ -1215,13 +1214,13 @@
Protobuf::FieldDescriptor->new(
name => 'large_uint32', index => 1, number => 2,
type => 13, cpp_type => 3, label => 1,
- default_value => Math::BigInt->new("4294967295"),
+ default_value => 4294967295,
message_type => undef, enum_type => undef, containing_type => undef,
is_extension => FALSE, extension_scope => undef),
Protobuf::FieldDescriptor->new(
name => 'large_uint64', index => 2, number => 3,
type => 4, cpp_type => 4, label => 1,
- default_value => Math::BigInt->new("18446744073709551615"),
+ default_value => Protobuf::Types::BI("18446744073709551615"),
message_type => undef, enum_type => undef, containing_type => undef,
is_extension => FALSE, extension_scope => undef),
Protobuf::FieldDescriptor->new(
@@ -1233,7 +1232,7 @@
Protobuf::FieldDescriptor->new(
name => 'small_int64', index => 4, number => 5,
type => 3, cpp_type => 2, label => 1,
- default_value => Math::BigInt->new("-9223372036854775807"),
+ default_value => Protobuf::Types::BI("-9223372036854775807"),
message_type => undef, enum_type => undef, containing_type => undef,
is_extension => FALSE, extension_scope => undef),
Protobuf::FieldDescriptor->new(

Modified: trunk/perl/t/data/memcache_service.proto
==============================================================================
--- trunk/perl/t/data/memcache_service.proto (original)
+++ trunk/perl/t/data/memcache_service.proto Tue Sep 2 13:42:04 2008
@@ -13,7 +13,8 @@
// Generates AppEngine/Service.pm with
// AppEngine::Service::MemcacheGetRequest, etc all inside. If
// unspecified, defaults to mapping file_name.proto to FileName.pm
-option perl_package = "AppEngine::Service";
+option perl_message_package = "AppEngine::Service";
+option perl_file_package = "AppEngine::Service::MemcacheProto";

message MemcacheServiceError {
enum ErrorCode {

Modified: trunk/perl/t/decoder.t
==============================================================================
--- trunk/perl/t/decoder.t (original)
+++ trunk/perl/t/decoder.t Tue Sep 2 13:42:04 2008
@@ -7,6 +7,7 @@

use lib "t/lib";
use Test::Protobuf;
+use Protobuf::Types qw(BI);

use FindBin qw($Bin);
use lib "$Bin/autogen";

Modified: trunk/perl/t/encoder.t
==============================================================================
--- trunk/perl/t/encoder.t (original)
+++ trunk/perl/t/encoder.t Tue Sep 2 13:42:04 2008
@@ -8,6 +8,7 @@
use lib "t/lib";
use Test::Protobuf;

+use Protobuf::Types qw(BI);

use_ok("Protobuf::Encoder");


Modified: trunk/perl/t/lib/Test/Protobuf.pm
==============================================================================
--- trunk/perl/t/lib/Test/Protobuf.pm (original)
+++ trunk/perl/t/lib/Test/Protobuf.pm Tue Sep 2 13:42:04 2008
@@ -8,22 +8,7 @@
use Test::More;
use Protobuf::Types;

-our @EXPORT = qw(escaped bin_is BI);
-
-sub BI {
- my $v = $_[0];
- if ( HAS_QUADS ) {
- return 0+$v if $v !~ /\D/;
- if ( $v =~ /^0x/ ) {
- my ( $high, $low ) = unpack("NN", pack("H*", substr($v,2)));
- return ( $high << 32 | $low );
- } else {
- die "unknown number format: $v";
- }
- } else {
- return Math::BigInt->new($_[0]);
- }
-}
+our @EXPORT = qw(escaped bin_is);

sub escaped {
my $v = shift;

Modified: trunk/perl/t/wire-format.t
==============================================================================
--- trunk/perl/t/wire-format.t (original)
+++ trunk/perl/t/wire-format.t Tue Sep 2 13:42:04 2008
@@ -6,6 +6,8 @@
use lib "t/lib";
use Test::Protobuf;

+use Protobuf::Types qw(BI);
+
use_ok("Protobuf::WireFormat");
my $F;


Modified: trunk/perl/t/wire-numbers.t
==============================================================================
--- trunk/perl/t/wire-numbers.t (original)
+++ trunk/perl/t/wire-numbers.t Tue Sep 2 13:42:04 2008
@@ -56,7 +56,12 @@

['int64', 7, "\x10"."\x07"],
['int64', -7, "\x10"."\xf9\xff\xff\xff\xff\xff\xff\xff\xff\x01"],
- ['int64',
0-(BI(2)**63), "\x10"."\x80\x80\x80\x80\x80\x80\x80\x80\x80\x01"],
+ ['int64',
BI("0x7fffffffffffffff"), "\x10"."\xff\xff\xff\xff\xff\xff\xff\xff\x7f"],
+ # This is a weird case, because it's a negative number whose
+ # corresponding positive number doesn't fit in 64 bits.
+ # 2**63 as a >64bit number is 0x8000000000000000, which when
+ # truncated to 64 bits and viewed as signed is -(2**63).
+ ['int64', int(0-(BI("0xffffffffffffffff") &
BI(2)**63)), "\x10"."\x80\x80\x80\x80\x80\x80\x80\x80\x80\x01"],

['uint32', $max_u32, "\x18"."\xff\xff\xff\xff\x0f"],
['uint32', 7, "\x18"."\x07"],

Modified: trunk/protobuf/src/google/protobuf/compiler/perl/perl_generator.cc
==============================================================================
--- trunk/protobuf/src/google/protobuf/compiler/perl/perl_generator.cc
(original)
+++ trunk/protobuf/src/google/protobuf/compiler/perl/perl_generator.cc Tue
Sep 2 13:42:04 2008
@@ -81,7 +81,7 @@
const char kDescriptorKey[] = "DESCRIPTOR";


-// Prints the common boilerplate needed at the top of every .py
+// Prints the common boilerplate needed at the top of every .pm
// file output by this generator.
void PrintTopBoilerplate(io::Printer* printer) {
printer->Print(
@@ -90,7 +90,8 @@
"use strict;\n"
"use warnings;\n"
"use 5.6.1;\n"
- "use Protobuf;"
+ "use Protobuf;\n"
+ "use Protobuf::Types;\n"
"\n");
}

@@ -108,6 +109,10 @@
descriptor.number());
}

+// Use the BI helper function to set "big int" (64 bit) numeric fields
+string BI(const string& numeric_string) {
+ return "Protobuf::Types::BI(\"" + numeric_string + "\")";
+}

// Returns a Perl literal giving the default value for a field.
// If the field specifies no explicit default value, we'll return
@@ -125,9 +130,9 @@
case FieldDescriptor::CPPTYPE_UINT32:
return SimpleItoa(field.default_value_uint32());
case FieldDescriptor::CPPTYPE_INT64:
- return SimpleItoa(field.default_value_int64());
+ return BI(SimpleItoa(field.default_value_int64()));
case FieldDescriptor::CPPTYPE_UINT64:
- return SimpleItoa(field.default_value_uint64());
+ return BI(SimpleItoa(field.default_value_uint64()));
case FieldDescriptor::CPPTYPE_DOUBLE:
return SimpleDtoa(field.default_value_double());
case FieldDescriptor::CPPTYPE_FLOAT:

Reply all
Reply to author
Forward
0 new messages