Thanks for you reply.
I think we use protobuf in the same way. Although we don't put the type id 
in the default proto file, we put the mapping in the config file.

But I think there should be a more elegance way to use protobuf, like my 
question in the stackoverflow

http://stackoverflow.com/questions/32173479/multiple-different-protobuf-messages-in-a-socket/32176485#32176485

maybe we should use a bigMessage to store the different proto message

On Monday, August 24, 2015 at 1:11:30 PM UTC+8, Michael Haberler wrote:
>
> 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 陈宗志 <bao...@gmail.com <javascript:>>: 
> > 
> > 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+u...@googlegroups.com <javascript:>. 
> > To post to this group, send email to prot...@googlegroups.com 
> <javascript:>. 
> > 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