Re: [protobuf] How could I get service, rpc request & response, message types at runtime?

42 views
Skip to first unread message

Dan Schmidt Valle

unread,
May 20, 2013, 12:17:34 PM5/20/13
to 李俊彦, prot...@googlegroups.com
I would suggest that you include the type of request/response in your messages. You could perhaps have an enum with your message types and that way you can check once you parse the message. Of course this means that you might need to use optionals for the payload of your message. Parsing to identify the type of message is frowned upon as all messages with the same structure parse as the same thing. Reflection is mostly used in my experience to query the structure of an already identified message. 

An idea could be to have for both request and response a structure like this:

message Rpc1 { ... }
message Rpc2 { ... }
message RpcMessage {
  required uint32 message_type = 1;
  optional Rpc1 rpc1 = 2;
  optional Rpc2 rpc2 = 3;
}





On 20 May 2013 08:36, 李俊彦 <gig...@gmail.com> wrote:
take a simple example:

message MyRequest
{
    required uint32 Request = 1;
}

message MyResponse
{
    required uint32 Response = 1;
}

service MyService
{
    rpc MyRpc(MyRequest) returns (MyResponse)
}


if I have string "MyService" and "MyRpc", and binary data for MyRequest and MyResponse,
how could I get known that the request is type "MyRequest" and the response is type "MyResponse" and then
construct objects of "MyRequest" & "MyResponse" to parse the binary data?

is it so called reflection?

--
You received this message because you are subscribed to the Google Groups "Protocol Buffers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to protobuf+u...@googlegroups.com.
To post to this group, send email to prot...@googlegroups.com.
Visit this group at http://groups.google.com/group/protobuf?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Reply all
Reply to author
Forward
0 new messages