aboutsummaryrefslogtreecommitdiffstats
path: root/generator
diff options
context:
space:
mode:
authorBernhard Krämer <bdkrae@gmail.com>2016-10-09 20:26:28 +0200
committerBernhard Krämer <bdkrae@gmail.com>2016-10-09 20:26:28 +0200
commitba97926cfd1e82bd294cf5e484633850d8e0b368 (patch)
tree41aa38edf6cf9b87e318287b6497a01940700551 /generator
parent91bb64a47b36b112c9b22391ef76fab29cf2cffc (diff)
Add proto3 option to handle singular fields
Diffstat (limited to 'generator')
-rwxr-xr-xgenerator/nanopb_generator.py12
-rw-r--r--generator/proto/nanopb.proto3
2 files changed, 10 insertions, 5 deletions
diff --git a/generator/nanopb_generator.py b/generator/nanopb_generator.py
index 973c7610..185a97bb 100755
--- a/generator/nanopb_generator.py
+++ b/generator/nanopb_generator.py
@@ -258,16 +258,18 @@ class Field:
# Check field rules, i.e. required/optional/repeated.
can_be_static = True
- if desc.label == FieldD.LABEL_REQUIRED:
- self.rules = 'REQUIRED'
- elif desc.label == FieldD.LABEL_OPTIONAL:
- self.rules = 'OPTIONAL'
- elif desc.label == FieldD.LABEL_REPEATED:
+ if desc.label == FieldD.LABEL_REPEATED:
self.rules = 'REPEATED'
if self.max_count is None:
can_be_static = False
else:
self.array_decl = '[%d]' % self.max_count
+ elif field_options.HasField("proto3"):
+ self.rules = 'SINGULAR'
+ elif desc.label == FieldD.LABEL_REQUIRED:
+ self.rules = 'REQUIRED'
+ elif desc.label == FieldD.LABEL_OPTIONAL:
+ self.rules = 'OPTIONAL'
else:
raise NotImplementedError(desc.label)
diff --git a/generator/proto/nanopb.proto b/generator/proto/nanopb.proto
index 8aab19a1..b9961c88 100644
--- a/generator/proto/nanopb.proto
+++ b/generator/proto/nanopb.proto
@@ -66,6 +66,9 @@ message NanoPBOptions {
// decode oneof as anonymous union
optional bool anonymous_oneof = 11 [default = false];
+
+ // Proto3 singular field does not generate a "has_" flag
+ optional bool proto3 = 12 [default = false];
}
// Extensions to protoc 'Descriptor' type in order to define options