Re: [protobuf] encoding: how to distinguish message and the field

2013-05-29 Thread mimocroc
Thanks for your answer!

(My mistake because I am checked my code on the example binary, generated 
by add_person_cpp, who (apparently) puts each message into a separate 
message-formatted container.)


четверг, 30 мая 2013 г., 1:13:21 UTC+8 пользователь Ilia Mirkin написал:
>
> Messages aren't preceded by anything. A message inside of a message is 
> preceeded by a varint that indicates its length (there's also a 
> deprecated begin/end group mechanism that you probably don't have to 
> worry about supporting). Then, for that length after the varint, 
> decoding of the sub-message should occur. So if you have 
>
> message A { 
>   optional B b = 1; 
>   optional int32 a = 2; 
> } 
>
> message B { 
>   optional int32 x = 2; 
> } 
>
> Then the byte sequence for A might be: 
>
>   
>indication that it's a varint>  
>
> Where the "varint len of b" is a varint equal to the length of " with indication that it's a varint> ". (And of course 
> remember that the tags start with a 4-bit header that indicates the 
> general type of the tag, like varint, length-delimited, fixed32/64, 
> and there are special provisions for tags < 16 so that they fit into a 
> single byte. Take a look at WireFormatLite -- it has a lot of good 
> helper functions.) 
>
> Hope that helps, 
>
>   -ilia 
>
>
> On Sun, May 26, 2013 at 12:35 PM, mimocroc 
> > 
> wrote: 
> > Hi! 
> > 
> > I am writing my own library for working with protobuf for D language 
> > (dlang.org) and have a question: 
> > 
> > Each message is preceded by a header in the "length delimited" format 
> and 
> > has tag which contains number of field. How I can distinguish message 
> header 
> > with field number and real field tagged with the same number? After all, 
> (as 
> > I understand it) theoretically any fields can be repeated at random 
> > locations in the message. 
> > 
> > Thanks. 
> > 
> > -- 
> > 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. 
> > 
> > 
>

-- 
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?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




Re: [protobuf] encoding: how to distinguish message and the field

2013-05-29 Thread Ilia Mirkin
Messages aren't preceded by anything. A message inside of a message is
preceeded by a varint that indicates its length (there's also a
deprecated begin/end group mechanism that you probably don't have to
worry about supporting). Then, for that length after the varint,
decoding of the sub-message should occur. So if you have

message A {
  optional B b = 1;
  optional int32 a = 2;
}

message B {
  optional int32 x = 2;
}

Then the byte sequence for A might be:

 
   

Where the "varint len of b" is a varint equal to the length of " ". (And of course
remember that the tags start with a 4-bit header that indicates the
general type of the tag, like varint, length-delimited, fixed32/64,
and there are special provisions for tags < 16 so that they fit into a
single byte. Take a look at WireFormatLite -- it has a lot of good
helper functions.)

Hope that helps,

  -ilia


On Sun, May 26, 2013 at 12:35 PM, mimocroc  wrote:
> Hi!
>
> I am writing my own library for working with protobuf for D language
> (dlang.org) and have a question:
>
> Each message is preceded by a header in the "length delimited" format and
> has tag which contains number of field. How I can distinguish message header
> with field number and real field tagged with the same number? After all, (as
> I understand it) theoretically any fields can be repeated at random
> locations in the message.
>
> Thanks.
>
> --
> 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?hl=en.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>

-- 
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?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




[protobuf] encoding: how to distinguish message and the field

2013-05-29 Thread mimocroc
Hi!

I am writing my own library for working with protobuf for D language 
(dlang.org) and have a question:

Each message is preceded by a header in the "length delimited" format and 
has tag which contains number of field. How I can distinguish message 
header with field number and real field tagged with the same number? After 
all, (as I understand it) theoretically any fields can be repeated at 
random locations in the message.

Thanks.

-- 
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?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.