From 1d7f60fec30678ec7403786808026444a4b901e6 Mon Sep 17 00:00:00 2001 From: Petteri Aimonen Date: Sun, 20 Jul 2014 14:56:12 +0300 Subject: Add skip_message option to generator. Update issue 121 Status: FixedInGit --- generator/nanopb_generator.py | 4 ++++ generator/proto/nanopb.proto | 3 +++ tests/options/options.expected | 3 +++ tests/options/options.proto | 10 +++++++--- 4 files changed, 17 insertions(+), 3 deletions(-) diff --git a/generator/nanopb_generator.py b/generator/nanopb_generator.py index 8ef4f187..2d2071e1 100755 --- a/generator/nanopb_generator.py +++ b/generator/nanopb_generator.py @@ -639,6 +639,10 @@ def parse_file(fdesc, file_options): for names, message in iterate_messages(fdesc, base_name): message_options = get_nanopb_suboptions(message, file_options, names) + + if message_options.skip_message: + continue + messages.append(Message(names, message, message_options)) for enum in message.enum_type: enum_options = get_nanopb_suboptions(enum, message_options, names + enum.name) diff --git a/generator/proto/nanopb.proto b/generator/proto/nanopb.proto index 2be2f803..9a4d6578 100644 --- a/generator/proto/nanopb.proto +++ b/generator/proto/nanopb.proto @@ -37,6 +37,9 @@ message NanoPBOptions { // Note: this cannot be used on CPUs that break on unaligned // accesses to variables. optional bool packed_struct = 5 [default = false]; + + // Skip this message + optional bool skip_message = 6 [default = false]; } // Extensions to protoc 'Descriptor' type in order to define options diff --git a/tests/options/options.expected b/tests/options/options.expected index e6179a27..dbd279ba 100644 --- a/tests/options/options.expected +++ b/tests/options/options.expected @@ -5,3 +5,6 @@ pb_callback_t int32_callback; \sEnumValue1 = 1 Message5_EnumValue1 } pb_packed my_packed_struct; +! skipped_field +! SkippedMessage + diff --git a/tests/options/options.proto b/tests/options/options.proto index b5badcfd..a8e557be 100644 --- a/tests/options/options.proto +++ b/tests/options/options.proto @@ -63,11 +63,15 @@ message my_packed_struct } // Message with ignored field -// Note: doesn't really test if the field is missing in the output, -// but atleast tests that the output compiles. message Message6 { required int32 field1 = 1; - optional int32 field2 = 2 [(nanopb).type = FT_IGNORE]; + optional int32 skipped_field = 2 [(nanopb).type = FT_IGNORE]; } +// Message that is skipped +message SkippedMessage +{ + option (nanopb_msgopt).skip_message = true; + required int32 foo = 1; +} -- cgit 1.2.3-korg