This is exactly what extensions are for -- see
http://code.google.com/apis/protocolbuffers/docs/proto.html#extensions

It would look something like:

message BaseMessage {
  required MsgType type = 1;
  extensions 100 to 1000000000;
}

Then each module would have a message like:

message Msg1 {
  extend BaseMessage {
    optional Msg1 msg1 = <some_unique_id>
  }
  required int32 field = 1;
}

Then the main program can pass the entire BaseMessage to the right module
based on type, and the module can retrieve the parsed extension.

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.com>
> .
> 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.

Reply via email to