Fix message length calculation for arrays of size 1 (issue #253)
authorPetteri Aimonen <jpa@git.mail.kapsi.fi>
Tue, 28 Mar 2017 20:20:31 +0000 (23:20 +0300)
committerPetteri Aimonen <jpa@git.mail.kapsi.fi>
Tue, 28 Mar 2017 20:20:31 +0000 (23:20 +0300)
generator/nanopb_generator.py

index 359e184..42669ac 100755 (executable)
@@ -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
         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
 
             encsize *= self.max_count
 
+            if self.max_count == 1:
+                encsize += 1
+
         return encsize
 
 
         return encsize