summaryrefslogtreecommitdiffstats
path: root/example_unions/unionproto.proto
diff options
context:
space:
mode:
authorPetteri Aimonen <jpa@git.mail.kapsi.fi>2012-06-16 14:08:40 +0300
committerPetteri Aimonen <jpa@git.mail.kapsi.fi>2012-06-16 14:08:40 +0300
commit0f1d5cca59a2fddcf6bc627bb35e207bf3889547 (patch)
treefc3172c5fd6e2a542e0686e36f5fc0420af23774 /example_unions/unionproto.proto
parente18352d50678005c9dbb3ac76913555f5317c81c (diff)
Added example on how to handle unions.
Diffstat (limited to 'example_unions/unionproto.proto')
-rw-r--r--example_unions/unionproto.proto30
1 files changed, 30 insertions, 0 deletions
diff --git a/example_unions/unionproto.proto b/example_unions/unionproto.proto
new file mode 100644
index 00000000..d7c9de2d
--- /dev/null
+++ b/example_unions/unionproto.proto
@@ -0,0 +1,30 @@
+// This is an example of how to handle 'union' style messages
+// with nanopb, without allocating memory for all the message types.
+//
+// There is no official type in Protocol Buffers for describing unions,
+// but they are commonly implemented by filling out exactly one of
+// several optional fields.
+
+message MsgType1
+{
+ required int32 value = 1;
+}
+
+message MsgType2
+{
+ required bool value = 1;
+}
+
+message MsgType3
+{
+ required int32 value1 = 1;
+ required int32 value2 = 2;
+}
+
+message UnionMessage
+{
+ optional MsgType1 msg1 = 1;
+ optional MsgType2 msg2 = 2;
+ optional MsgType3 msg3 = 3;
+}
+