From 25210ac1419567178502e99f005ddb49c4e63d21 Mon Sep 17 00:00:00 2001 From: Petteri Aimonen Date: Tue, 28 Mar 2017 23:20:31 +0300 Subject: Fix message length calculation for arrays of size 1 (issue #253) --- generator/nanopb_generator.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/generator/nanopb_generator.py b/generator/nanopb_generator.py index 359e1849..42669ace 100755 --- a/generator/nanopb_generator.py +++ b/generator/nanopb_generator.py @@ -649,9 +649,14 @@ class Field: if self.rules == 'REPEATED': # Decoders must be always able to handle unpacked arrays. # Therefore we have to reserve space for it, even though - # we emit packed arrays ourselves. + # we emit packed arrays ourselves. For length of 1, packed + # arrays are larger however so we need to add allowance + # for the length byte. encsize *= self.max_count + if self.max_count == 1: + encsize += 1 + return encsize -- cgit 1.2.3-korg