From 7f1e0ec17987ff10c5ce17f347b66423fe8ac4bd Mon Sep 17 00:00:00 2001 From: Petteri Aimonen Date: Mon, 5 Oct 2015 16:01:53 +0300 Subject: 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. --- generator/nanopb_generator.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'generator') 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') -- cgit 1.2.3-korg