Retrieve a message field from a stream

79 views
Skip to first unread message

Barzo

unread,
Jan 23, 2013, 6:53:36 AM1/23/13
to prot...@googlegroups.com
Hi,

I'm trying to implement a system like described here where I have a Type List of Messages.
Now, when I receive a message from an endpoint, I need a way to retrieve the message opCode (which is a filed contained in all messages) to build my message template class.

My .proto is like this:

enum EMessages
{
  E_MSG_METHOD_CONNECT  = 0x8001;
  E_MSG_EVENT_CONNECT   = 0xA001;
  ....
}

message MsgHeader
{
  required google.protobuf.FileDescriptorSet  proto_files = 1;
  required long  sessionRef    = 3;
  optional long   transactionId = 4 [default = 0];
  optional long   status        = 5 [default = 0];
}

message MSG_METHOD_CONNECT
{
  optional EMessages    opCode = 1 [default = E_MSG_METHOD_CONNECT];
  required MsgHeader    header = 2;
  ... other fields ...
}

message MSG_EVENT_CONNECT
{
  optional EMessages    opCode = 1 [default = E_MSG_EVENT_CONNECT];
  required MsgHeader    header = 2;
  ... other fields ...
}

So each message contains the opCode field.
Is there a way to retrieve the opCode value from a received stream?

Regards,
Daniele.

Feng Xiao

unread,
Jan 25, 2013, 1:15:58 AM1/25/13
to prot...@googlegroups.com
So you want to use the opCode value to distinguish which message is sent?
The common practice is that you always send the sam message over the wire, like this:
message TheOneMessageSentOverTheWire {
  optional EMessages opCode = 1;
  optional MSG_METHOD_CONNECT message1 = 2;
  optional MSG_EVENT_CONNECT message 2 = 3;
  ...
}

 

Regards,
Daniele.

Barzo

unread,
Jan 30, 2013, 10:36:04 AM1/30/13
to prot...@googlegroups.com

So you want to use the opCode value to distinguish which message is sent?
The common practice is that you always send the sam message over the wire, like this:
message TheOneMessageSentOverTheWire {
  optional EMessages opCode = 1;
  optional MSG_METHOD_CONNECT message1 = 2;
  optional MSG_EVENT_CONNECT message 2 = 3;
  ...
}

Dear Feng,

first, thanks for your reply! 
So you suggest to send ALWAYS every message? It sound strange to me! :-)
Is not too verbose? For example if I have 50 or more messages...?

Daniele.

Christopher Head

unread,
Jan 30, 2013, 3:51:36 PM1/30/13
to prot...@googlegroups.com
Those messages are optional. You will only send one, the one that you
actually add. The others take up no space in the serialized data stream.

Chris

Barzo

unread,
Jan 31, 2013, 5:48:47 AM1/31/13
to prot...@googlegroups.com

Those messages are optional. You will only send one, the one that you
actually add. The others take up no space in the serialized data stream.

Chris

Hi Chris,

of course, you're right! I'm only new on this way of implementation! :-)
But I will adapt to it, if it's the best way!

Daniele.
Reply all
Reply to author
Forward
0 new messages