aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPetteri Aimonen <jpa@git.mail.kapsi.fi>2014-02-04 20:24:44 +0200
committerPetteri Aimonen <jpa@git.mail.kapsi.fi>2014-02-04 20:24:44 +0200
commita2f8112166d73aaf7e8fc877f0310202319d4639 (patch)
tree190250cd73fd9140380383d67fc8ec26e3430c61
parent5efeb392e00a57accb849904aba8dbc092c4076a (diff)
Add proper suffixes for integer default values.
Update issue 102 Status: FixedInGit
-rwxr-xr-xgenerator/nanopb_generator.py6
-rw-r--r--tests/alltypes/alltypes.proto20
2 files changed, 16 insertions, 10 deletions
diff --git a/generator/nanopb_generator.py b/generator/nanopb_generator.py
index 094f8e85..4f8ed94c 100755
--- a/generator/nanopb_generator.py
+++ b/generator/nanopb_generator.py
@@ -315,6 +315,12 @@ class Field:
data = self.default.decode('string_escape')
data = ['0x%02x' % ord(c) for c in data]
default = '{%d, {%s}}' % (len(data), ','.join(data))
+ elif self.pbtype in ['FIXED32', 'UINT32']:
+ default += 'u'
+ elif self.pbtype in ['FIXED64', 'UINT64']:
+ default += 'ull'
+ elif self.pbtype in ['SFIXED64', 'INT64']:
+ default += 'll'
if declaration_only:
return 'extern const %s %s_default%s;' % (ctype, self.struct_name + self.name, array_decl)
diff --git a/tests/alltypes/alltypes.proto b/tests/alltypes/alltypes.proto
index 234b7236..6e5425a3 100644
--- a/tests/alltypes/alltypes.proto
+++ b/tests/alltypes/alltypes.proto
@@ -14,16 +14,16 @@ enum HugeEnum {
}
message Limits {
- required int32 int32_min = 1;
- required int32 int32_max = 2;
- required uint32 uint32_min = 3;
- required uint32 uint32_max = 4;
- required int64 int64_min = 5;
- required int64 int64_max = 6;
- required uint64 uint64_min = 7;
- required uint64 uint64_max = 8;
- required HugeEnum enum_min = 9;
- required HugeEnum enum_max = 10;
+ required int32 int32_min = 1 [default = 2147483647];
+ required int32 int32_max = 2 [default = -2147483648];
+ required uint32 uint32_min = 3 [default = 4294967295];
+ required uint32 uint32_max = 4 [default = 0];
+ required int64 int64_min = 5 [default = 9223372036854775807];
+ required int64 int64_max = 6 [default = -9223372036854775807]; /* GCC gives a warning about -2**63, so just avoid the trouble for now.. */
+ required uint64 uint64_min = 7 [default = 18446744073709551615];
+ required uint64 uint64_max = 8 [default = 0];
+ required HugeEnum enum_min = 9 [default = Positive];
+ required HugeEnum enum_max = 10 [default = Negative];
}
enum MyEnum {