Re: [protobuf] Can a message derive from another message?

2011-03-02 Thread Jason Hsueh
No, message inheritance is not supported. Have a look at
http://code.google.com/apis/protocolbuffers/docs/techniques.html#union and
see if that solves your use case.

On Wed, Mar 2, 2011 at 7:04 AM, ZHOU Xiaobo  wrote:

> Hi:
>   My problem is that when I receive a packet I have to check one field( say
> 'int32 COMMAND' ) to decide
> the type of the inner packet. For example:
>
> message OutterPkt {
>required fiexed32 Length = 1;
>required int32 COMMAND = 2;
>required string Content = 3;
> }
>
> message InnerPktA {
> required int32 UserID;
> required int16 UserGender;
> }
>
> message InnerPktB {
>required string UserName = 1;
>reruired string UserDescripton = 2;
> }
>
> my code to process this packet will be:
>
> ..
> OuuterPkt outp;
> outp.ParseFromString(inputbuf);
> if (outp.COMMAND == 1) {
>InnerPktA pkta;
>pkta.ParseFromString(outp.Content());
>..
> } else if (outp.COMMAND == 2) {
>InnerPktB pktb;
>pktb.ParseFromString(outp.Content());
>..
> } else {
>
> }
>
>
> My question is: I think the pseudo code above is not efficient because it
> parses the buffer twice and there are too many memcpy.
> Is there a better way to deal with this situation?
> thanks.X
>
> --
> You received this message because you are subscribed to the Google Groups
> "Protocol Buffers" group.
> To post to this group, send email to protobuf@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.
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Protocol Buffers" group.
To post to this group, send email to protobuf@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.



Re: [protobuf] Can a message derive from another message?

2011-03-03 Thread Evan Jones

On 03/02/2011 10:04 AM, ZHOU Xiaobo wrote:

 required string Content = 3;


WARNING: You should be using type bytes here, not type string. This 
doesn't matter for C++, but matters for other languages which will 
assume strings contain UTF-8 data.


Evan

--
http://evanjones.ca/

--
You received this message because you are subscribed to the Google Groups "Protocol 
Buffers" group.
To post to this group, send email to protobuf@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.



Re: [protobuf] Can a message derive from another message?

2011-03-03 Thread ZHOU Xiaobo
thank you.
It sounds like what I am looking for




No, message inheritance is not supported. Have a look at
http://code.google.com/apis/protocolbuffers/docs/techniques.html#union and
see if that solves your use case.

On Wed, Mar 2, 2011 at 7:04 AM, ZHOU Xiaobo  wrote:

> Hi:
>   My problem is that when I receive a packet I have to check one field( say
> 'int32 COMMAND' ) to decide
> the type of the inner packet. For example:
>
> message OutterPkt {
>required fiexed32 Length = 1;
>required int32 COMMAND = 2;
>required string Content = 3;
> }
>
> message InnerPktA {
> required int32 UserID;
> required int16 UserGender;
> }
>
> message InnerPktB {
>required string UserName = 1;
>reruired string UserDescripton = 2;
> }
>
> my code to process this packet will be:
>
> ..
> OuuterPkt outp;
> outp.ParseFromString(inputbuf);
> if (outp.COMMAND == 1) {
>InnerPktA pkta;
>pkta.ParseFromString(outp.Content());
>..
> } else if (outp.COMMAND == 2) {
>InnerPktB pktb;
>pktb.ParseFromString(outp.Content());
>..
> } else {
>
> }
>
>
> My question is: I think the pseudo code above is not efficient because it
> parses the buffer twice and there are too many memcpy.
> Is there a better way to deal with this situation?
> thanks.X
>
> --
> You received this message because you are subscribed to the Google Groups
> "Protocol Buffers" group.
> To post to this group, send email to protobuf@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.
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Protocol Buffers" group.
To post to this group, send email to protobuf@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.



Re: [protobuf] Can a message derive from another message?

2011-03-03 Thread ZHOU Xiaobo
thanks

On 03/02/2011 10:04 AM, ZHOU Xiaobo wrote:
>  required string Content = 3;

WARNING: You should be using type bytes here, not type string. This 
doesn't matter for C++, but matters for other languages which will 
assume strings contain UTF-8 data.

Evan

-- 
http://evanjones.ca/

-- 
You received this message because you are subscribed to the Google Groups 
"Protocol Buffers" group.
To post to this group, send email to protobuf@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.