From ca74746e23b5a9e7916e8fde6632d71d61603f50 Mon Sep 17 00:00:00 2001 From: Petteri Aimonen Date: Mon, 20 Feb 2017 15:47:44 +0200 Subject: Add new option max_length for strings (issue #107) Max_size is the allocated size, so users had to add +1 for the null terminator. Max_length does the +1 automatically in the generator. --- generator/nanopb_generator.py | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'generator/nanopb_generator.py') 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 -- cgit 1.2.3-korg