Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nanopb/nanopb.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorReinis Veips <reinis.veips@atlasaero.space>2024-01-05 11:00:26 +0300
committerPetteri Aimonen <jpa@github.mail.kapsi.fi>2024-01-05 20:31:23 +0300
commite163b3395d91f930146b27cb8e666498ce8c4102 (patch)
tree903903bce7f669cb21eb70269c2b14e76e517a21
parent7421969cde854dd1b6b2df28a8c6474347bb87ca (diff)
--cpp-descriptors: add has_msgid() and msgid() methods
-rwxr-xr-xgenerator/nanopb_generator.py6
-rw-r--r--tests/cxx_descriptor/message.proto10
-rw-r--r--tests/cxx_descriptor/message_descriptor.cc6
3 files changed, 22 insertions, 0 deletions
diff --git a/generator/nanopb_generator.py b/generator/nanopb_generator.py
index ff429bf..062d54a 100755
--- a/generator/nanopb_generator.py
+++ b/generator/nanopb_generator.py
@@ -1525,6 +1525,12 @@ class Message(ProtoElement):
result += ' static inline const pb_msgdesc_t* fields() {\n'
result += ' return &%s_msg;\n' % (self.name)
result += ' }\n'
+ result += ' static inline bool has_msgid() {\n'
+ result += ' return %s;\n' % ("true" if hasattr(self, "msgid") else "false", )
+ result += ' }\n'
+ result += ' static inline int32_t msgid() {\n'
+ result += ' return %d;\n' % (getattr(self, "msgid", 0), )
+ result += ' }\n'
result += '};'
return result
diff --git a/tests/cxx_descriptor/message.proto b/tests/cxx_descriptor/message.proto
index be4334d..74f6b67 100644
--- a/tests/cxx_descriptor/message.proto
+++ b/tests/cxx_descriptor/message.proto
@@ -10,3 +10,13 @@ message MyEmptyMessage {
message MyNonEmptyMessage {
optional uint32 field = 1;
}
+
+message MyMessageWithMsgid {
+ option (nanopb_msgopt).msgid = 42;
+ optional uint32 field = 1;
+}
+
+message MyMessageWithoutMsgid {
+ optional uint32 field = 1;
+}
+
diff --git a/tests/cxx_descriptor/message_descriptor.cc b/tests/cxx_descriptor/message_descriptor.cc
index 4437301..04c63b3 100644
--- a/tests/cxx_descriptor/message_descriptor.cc
+++ b/tests/cxx_descriptor/message_descriptor.cc
@@ -23,6 +23,12 @@ extern "C" int main() {
TEST(MessageDescriptor<MyNonEmptyMessage>::fields() ==
MyNonEmptyMessage_fields);
+ TEST(MessageDescriptor<MyMessageWithMsgid>::has_msgid() == true);
+ TEST(MessageDescriptor<MyMessageWithMsgid>::msgid() == 42);
+
+ TEST(MessageDescriptor<MyMessageWithoutMsgid>::has_msgid() == false);
+
+
if (status != 0) fprintf(stdout, "\n\nSome tests FAILED!\n");
return status;