From d32d04ba1011806fe769f95dc2a88964f1102c6c Mon Sep 17 00:00:00 2001 From: Petteri Aimonen Date: Fri, 23 Jan 2015 21:29:29 +0200 Subject: Fix encoded_size #defines for oneof messages. The sizes are represented as EncodedSize() instances, which cause max() operation to sort them by address instead of value. This caused pretty much random item to be selected for the maximum. Update issue 141 Status: FixedInGit --- generator/nanopb_generator.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'generator/nanopb_generator.py') diff --git a/generator/nanopb_generator.py b/generator/nanopb_generator.py index 0d7be492..9750b670 100755 --- a/generator/nanopb_generator.py +++ b/generator/nanopb_generator.py @@ -641,7 +641,17 @@ class OneOf(Field): return max([f.largest_field_value() for f in self.fields]) def encoded_size(self, allmsgs): - return max([f.encoded_size(allmsgs) for f in self.fields]) + largest = EncodedSize(0) + for f in self.fields: + size = f.encoded_size(allmsgs) + if size is None: + return None + elif size.symbols: + return None # Cannot resolve maximum of symbols + elif size.value > largest.value: + largest = size + + return largest # --------------------------------------------------------------------------- # Generation of messages (structures) -- cgit 1.2.3-korg