If you are looking to tag messages with a type id, which protobuf has no native 
support for - this is what we've done:


we tag each message with an option which stores the type id like so: 
https://github.com/mhaberler/machinetalk-protobuf/blob/master/proto/object.proto#L15,
 those are manually assigned

if the msgid needs to go on the wire, we'll probably encode it as a varint 
prefixing the message, right after any length field
so we'd have 

   '<length as varint><type id as varint><serialized message>'

thanks to introspection the msgid can be retrieved given a descriptor, and used 
to find the proper descriptor on the receiving side, given the decoded varint


see the threads:
https://groups.google.com/forum/#!searchin/nanopb/msgid/nanopb/pZcrj-zbVEI/YM5Kcd6_aCMJ
https://groups.google.com/forum/#!searchin/nanopb/msgid/nanopb/TWm3vd1bJIg/3xcte_DiTSwJ


> Am 23.08.2015 um 21:10 schrieb 陈宗志 <baot...@gmail.com>:
> 
> I use protobuf wich my c++ server. But I have a problem with multiple 
> messages with socket
> 
> I define many proto messages, such as
> 
> message SdkHGetRet {
>   required int32 opcode = 1;
>   required bytes value = 2;
> }
> 
> message SdkHPut {
>   required bytes table = 1;
>   required bytes hname = 2;
>   required bytes key = 3;
>   required bytes value = 4;
>   optional int32 writesrc = 5 [default = 0];
> }
> 
> message SdkSet {
>   required bytes table = 1;
>   required bytes key = 2;
>   required bytes value = 3;
>   optional int32 writesrc = 5 [default = 0];
> }
> 
> message SdkSetRet {
>   required bool status = 1;
>   optional string master = 2;
> }
> 
> As you can see from here, I add every message with an opcode, so every time I 
> got a message, 
> 
> -- 
> 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+unsubscr...@googlegroups.com.
> To post to this group, send email to protobuf@googlegroups.com.
> Visit this group at http://groups.google.com/group/protobuf.
> For more options, visit https://groups.google.com/d/optout.

-- 
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+unsubscr...@googlegroups.com.
To post to this group, send email to protobuf@googlegroups.com.
Visit this group at http://groups.google.com/group/protobuf.
For more options, visit https://groups.google.com/d/optout.

Reply via email to