diff options
-rwxr-xr-x | generator/nanopb_generator.py | 16 | ||||
-rw-r--r-- | tests/regression/issue_188/SConscript | 6 | ||||
-rw-r--r-- | tests/regression/issue_188/oneof.proto | 29 |
3 files changed, 45 insertions, 6 deletions
diff --git a/generator/nanopb_generator.py b/generator/nanopb_generator.py index 13217462..62ee41bf 100755 --- a/generator/nanopb_generator.py +++ b/generator/nanopb_generator.py @@ -125,11 +125,15 @@ class EncodedSize: '''Class used to represent the encoded size of a field or a message. Consists of a combination of symbolic sizes and integer sizes.''' def __init__(self, value = 0, symbols = []): - if isinstance(value, strtypes + (Names,)): - symbols = [str(value)] - value = 0 - self.value = value - self.symbols = symbols + if isinstance(value, EncodedSize): + self.value = value.value + self.symbols = value.symbols + elif isinstance(value, strtypes + (Names,)): + self.symbols = [str(value)] + self.value = 0 + else: + self.value = value + self.symbols = symbols def __add__(self, other): if isinstance(other, int): @@ -728,7 +732,7 @@ class OneOf(Field): def encoded_size(self, dependencies): largest = EncodedSize(0) for f in self.fields: - size = f.encoded_size(dependencies) + size = EncodedSize(f.encoded_size(dependencies)) if size is None: return None elif size.symbols: diff --git a/tests/regression/issue_188/SConscript b/tests/regression/issue_188/SConscript new file mode 100644 index 00000000..6bc32712 --- /dev/null +++ b/tests/regression/issue_188/SConscript @@ -0,0 +1,6 @@ +# Regression test for issue with Enums inside OneOf. + +Import('env') + +env.NanopbProto('oneof') + diff --git a/tests/regression/issue_188/oneof.proto b/tests/regression/issue_188/oneof.proto new file mode 100644 index 00000000..e37f5c02 --- /dev/null +++ b/tests/regression/issue_188/oneof.proto @@ -0,0 +1,29 @@ +syntax = "proto2"; + +message MessageOne +{ + required uint32 one = 1; + required uint32 two = 2; + required uint32 three = 3; + required int32 four = 4; +} + +enum EnumTwo +{ + SOME_ENUM_1 = 1; + SOME_ENUM_2 = 5; + SOME_ENUM_3 = 6; + SOME_ENUM_4 = 9; + SOME_ENUM_5 = 10; + SOME_ENUM_6 = 12; + SOME_ENUM_7 = 39; + SOME_ENUM_8 = 401; +} + +message OneofMessage +{ + oneof payload { + MessageOne message = 1; + EnumTwo enum = 2; + } +} |