aboutsummaryrefslogtreecommitdiffstats
path: root/generator/nanopb_generator.py
diff options
context:
space:
mode:
authorPetteri Aimonen <jpa@git.mail.kapsi.fi>2015-01-23 21:29:29 +0200
committerPetteri Aimonen <jpa@git.mail.kapsi.fi>2015-01-23 21:29:29 +0200
commitd32d04ba1011806fe769f95dc2a88964f1102c6c (patch)
tree76eaed039e6dcf8502598c3b1d74a2c29ce4fb18 /generator/nanopb_generator.py
parent0286a0746ad6f6d525400f720e30d9d13913a556 (diff)
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
Diffstat (limited to 'generator/nanopb_generator.py')
-rwxr-xr-xgenerator/nanopb_generator.py12
1 files changed, 11 insertions, 1 deletions
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)