diff options
author | Petteri Aimonen <jpa@git.mail.kapsi.fi> | 2015-11-20 23:57:37 +0200 |
---|---|---|
committer | Petteri Aimonen <jpa@git.mail.kapsi.fi> | 2015-11-20 23:57:37 +0200 |
commit | 7af48e550f084aed929bb7db99070cb8f5d08210 (patch) | |
tree | 7b047610f5750cc8967446c132e1bc030680f0a8 /generator/nanopb_generator.py | |
parent | 990b7223ebfae4161ba4bf7ef81094f2317a665b (diff) |
Fix generator crash with Enum inside Oneof (issue #188).
Add testcase for the same.
Diffstat (limited to 'generator/nanopb_generator.py')
-rwxr-xr-x | generator/nanopb_generator.py | 16 |
1 files changed, 10 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: |