This is the way I initially thought to do it but the extensions seems like a much better idea. Is there any benefit of using an opaque data method over extensions.
On Nov 5, 2:15 pm, Jon Parise <j...@booyah.com> wrote: > Hi Adam, > > I needed to do something similar on a previous project. I stored the > serialized version of the type-specific message as opaque data ("bytes") in > an outer enveloping message. > > message Envelope > { > required MsgType type = 1; > required bytes data = 2; > > } > > Then you can create any type of message type hierarchy you like. You simply > write the serialized version of those messages into the 'data' field above > and switch based on the 'type' field. > > There are two immediate downsides to this approach: 1) a few bytes of > serialization overhead; and 2) the embedded message data is treated > opaquely, so it's slightly harder to inspect. > > — *Jon* > > > > > > > > On Fri, Nov 5, 2010 at 10:31 AM, AdamM <adammaga...@gmail.com> wrote: > > Hello PB Group, > > > I am programming a group of programs in C++ that use PB to > > communicate. In my first version of the program I was using a .proto > > file that looked similar to the example 1 below. I would then run a > > switch statement on a MsgType and create the proper message. > > > I am now starting to write my second version of the program to include > > a plugin module architecture. My program calls for a core program and > > then multiple modules that are written against a base module. Well in > > my core program I get packets over the network and then parse them > > info a PB Message. > > > I would like a way to have some sort of Base Message that the my core > > program would use to parse with the base message would contain a > > packet packet operation code and the data for the actual message > > structure. I want to program it so the Core program has no idea what > > the actual message structure is. It would pass it to the respective > > module based on the operation code who would then parse the actual > > message structure because it knows what that structure should be. > > > Does anyone have any suggestions how to do this? Any help would be > > much appreciated. > > > Example 1. > > > enum MsgType { > > MSG1, > > MSG2, > > MSG3 > > } > > > Message Msg1 { > > required int32 field = 1 ; > > } > > > Message Msg2 { > > required int32 field = 1 ; > > } > > > Message Msg3 { > > required int32 field = 1 ; > > } > > > Message BaseMessage { > > required MsgType type = 1 ; > > optional Msg1 = 2 ; > > optional Msg2 = 3 ; > > optional Msg3 = 4 ; > > } > > > -- > > You received this message because you are subscribed to the Google Groups > > "Protocol Buffers" group. > > To post to this group, send email to proto...@googlegroups.com. > > To unsubscribe from this group, send email to > > protobuf+unsubscr...@googlegroups.com<protobuf%2bunsubscr...@googlegroups.c > > om> > > . > > For more options, visit this group at > >http://groups.google.com/group/protobuf?hl=en. -- You received this message because you are subscribed to the Google Groups "Protocol Buffers" group. To post to this group, send email to proto...@googlegroups.com. To unsubscribe from this group, send email to protobuf+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/protobuf?hl=en.