summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rwxr-xr-xgenerator/nanopb_generator.py8
-rw-r--r--tests/options/SConscript5
-rw-r--r--tests/options/proto3_options.expected4
-rw-r--r--tests/options/proto3_options.proto11
4 files changed, 23 insertions, 5 deletions
diff --git a/generator/nanopb_generator.py b/generator/nanopb_generator.py
index 066ef936..a2ee22db 100755
--- a/generator/nanopb_generator.py
+++ b/generator/nanopb_generator.py
@@ -285,7 +285,7 @@ class Field:
can_be_static = False
else:
self.array_decl = '[%d]' % self.max_count
- elif field_options.HasField("proto3"):
+ elif field_options.proto3:
self.rules = 'SINGULAR'
elif desc.label == FieldD.LABEL_REQUIRED:
self.rules = 'REQUIRED'
@@ -1373,6 +1373,9 @@ def get_nanopb_suboptions(subdesc, options, name):
new_options = nanopb_pb2.NanoPBOptions()
new_options.CopyFrom(options)
+ if hasattr(subdesc, 'syntax') and subdesc.syntax == "proto3":
+ new_options.proto3 = True
+
# Handle options defined in a separate file
dotname = '.'.join(name.parts)
for namemask, options in Globals.separate_options:
@@ -1380,9 +1383,6 @@ def get_nanopb_suboptions(subdesc, options, name):
Globals.matched_namemasks.add(namemask)
new_options.MergeFrom(options)
- if hasattr(subdesc, 'syntax') and subdesc.syntax == "proto3":
- new_options.proto3 = True
-
# Handle options defined in .proto
if isinstance(subdesc.options, descriptor.FieldOptions):
ext_type = nanopb_pb2.nanopb
diff --git a/tests/options/SConscript b/tests/options/SConscript
index 89a00fa5..215e3bd0 100644
--- a/tests/options/SConscript
+++ b/tests/options/SConscript
@@ -4,6 +4,9 @@ Import("env")
env.NanopbProto("options")
env.Object('options.pb.c')
-
env.Match(['options.pb.h', 'options.expected'])
+env.NanopbProto("proto3_options")
+env.Object('proto3_options.pb.c')
+env.Match(['proto3_options.pb.h', 'proto3_options.expected'])
+
diff --git a/tests/options/proto3_options.expected b/tests/options/proto3_options.expected
new file mode 100644
index 00000000..cc2f29c0
--- /dev/null
+++ b/tests/options/proto3_options.expected
@@ -0,0 +1,4 @@
+! bool has_proto3_default
+bool has_proto3_off
+! bool has_proto3_on
+
diff --git a/tests/options/proto3_options.proto b/tests/options/proto3_options.proto
new file mode 100644
index 00000000..1017f046
--- /dev/null
+++ b/tests/options/proto3_options.proto
@@ -0,0 +1,11 @@
+syntax = "proto3";
+
+import "nanopb.proto";
+
+message Message1
+{
+ int32 proto3_default = 1;
+ int32 proto3_off = 2 [(nanopb).proto3 = false];
+ int32 proto3_on = 3 [(nanopb).proto3 = true];
+}
+