diff options
author | Petteri Aimonen <jpa@git.mail.kapsi.fi> | 2015-10-05 16:01:53 +0300 |
---|---|---|
committer | Petteri Aimonen <jpa@git.mail.kapsi.fi> | 2015-10-05 16:01:53 +0300 |
commit | 7f1e0ec17987ff10c5ce17f347b66423fe8ac4bd (patch) | |
tree | 968ebd9aa8ffcae0d45929a1c9bdc5abd2d02c86 /generator | |
parent | 6448f5d40d498a8de05b953f8318dba0cf4ff26f (diff) |
Fix regression in generating message size defines (issue #172).
This bug was triggered when:
1. A .proto file included another .proto from a different directory.
2. The another .proto has an associated .options file.
Added regression test for the same.
Diffstat (limited to 'generator')
-rwxr-xr-x | generator/nanopb_generator.py | 18 |
1 files changed, 9 insertions, 9 deletions
diff --git a/generator/nanopb_generator.py b/generator/nanopb_generator.py index 37f7beb5..bc388958 100755 --- a/generator/nanopb_generator.py +++ b/generator/nanopb_generator.py @@ -514,18 +514,18 @@ class Field: return None if self.pbtype == 'MESSAGE': + encsize = None if str(self.submsgname) in dependencies: submsg = dependencies[str(self.submsgname)] encsize = submsg.encoded_size(dependencies) - if encsize is None: - return None # Submessage size is indeterminate - - # Include submessage length prefix - encsize += varint_max_size(encsize.upperlimit()) - else: - # Submessage cannot be found, this currently occurs when - # the submessage type is defined in a different file and - # not using the protoc plugin. + if encsize is not None: + # Include submessage length prefix + encsize += varint_max_size(encsize.upperlimit()) + + if encsize is None: + # Submessage or its size cannot be found. + # This can occur if submessage is defined in different + # file, and it or its .options could not be found. # Instead of direct numeric value, reference the size that # has been #defined in the other file. encsize = EncodedSize(self.submsgname + 'size') |