Add new option max_length for strings (issue #107)
[apps/agl-service-can-low-level.git] / generator / nanopb_generator.py
index 6e5ebaf..ca60c03 100755 (executable)
@@ -270,6 +270,10 @@ class Field:
         # Parse field options
         if field_options.HasField("max_size"):
             self.max_size = field_options.max_size
+        
+        if desc.type == FieldD.TYPE_STRING and field_options.HasField("max_length"):
+            # max_length overrides max_size for strings
+            self.max_size = field_options.max_length + 1
 
         if field_options.HasField("max_count"):
             self.max_count = field_options.max_count