diff options
Diffstat (limited to 'generator')
-rwxr-xr-x | generator/nanopb_generator.py | 4 | ||||
-rw-r--r-- | generator/proto/nanopb.proto | 5 |
2 files changed, 9 insertions, 0 deletions
diff --git a/generator/nanopb_generator.py b/generator/nanopb_generator.py index 6e5ebaf9..ca60c03a 100755 --- a/generator/nanopb_generator.py +++ b/generator/nanopb_generator.py @@ -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 diff --git a/generator/proto/nanopb.proto b/generator/proto/nanopb.proto index f6fe4a20..7d39e1c3 100644 --- a/generator/proto/nanopb.proto +++ b/generator/proto/nanopb.proto @@ -32,8 +32,13 @@ enum IntSize { // fields. message NanoPBOptions { // Allocated size for 'bytes' and 'string' fields. + // For string fields, this should include the space for null terminator. optional int32 max_size = 1; + // Maximum length for 'string' fields. Setting this is equivalent + // to setting max_size to a value of length+1. + optional int32 max_length = 14; + // Allocated number of entries in arrays ('repeated' fields) optional int32 max_count = 2; |