diff options
author | Romain Forlot <romain.forlot@iot.bzh> | 2017-06-20 10:24:05 +0000 |
---|---|---|
committer | Romain Forlot <romain.forlot@iot.bzh> | 2017-06-20 10:24:05 +0000 |
commit | 32e25cbca210a359b09768537b6f443fe90a3070 (patch) | |
tree | 3309794c15d8a8f8e9c1c08cad072ee1378813ba /libs/nanopb/examples/using_union_messages/unionproto.proto | |
parent | 76c43dec62b2e21cd6446360c00d4fe6b437533f (diff) |
Separation Generator to a dedicated repo
Change-Id: Id94831651c3266861435272a6e36c7884bef2c45
Signed-off-by: Romain Forlot <romain.forlot@iot.bzh>
Diffstat (limited to 'libs/nanopb/examples/using_union_messages/unionproto.proto')
-rw-r--r-- | libs/nanopb/examples/using_union_messages/unionproto.proto | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/libs/nanopb/examples/using_union_messages/unionproto.proto b/libs/nanopb/examples/using_union_messages/unionproto.proto new file mode 100644 index 00000000..209df0d2 --- /dev/null +++ b/libs/nanopb/examples/using_union_messages/unionproto.proto @@ -0,0 +1,32 @@ +// 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. + +syntax = "proto2"; + +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; +} + |