On Thu, Jun 20, 2013 at 2:13 AM, Sébastien Muscat <seb.mus...@gmail.com>wrote:

> Hi,
>
> I've got an encoding question about the following proto :
>
> message Property {
>   required string key = 1;
>   optional string value = 2;
> }
>
> message SysDate {
>   required uint64 sec = 1;
>   required uint32 usec = 2;
> }
>
> message BuiltInTest {
>   required uint32 bit = 1;
>   required uint32 bit_status = 2;
>   required SysDate date = 3 ;
>   optional Property bit_properties = 16 ;
>   required string infos = 17;
> }
>
> then, I receive the following message
>
> 08 02 10 01 1A 08 08 EB 80 10 10 83 90 0A
> 82 01 10 0A A5 6B 65 79 12 07 76 61 6C 75 65
> 8A 01 05 69 6E 66 6F 73
>
> If I decode the first line, it's ok I got the value for bit, bit_status
> and date
> For the second line it's also ok, I got the values for bit_properties
> (with key attribute = "key" and value attribute = "value")
> And for the last line, I understand that byte 8A means wire type 2 and tag
> 17, byte 05 means a length of 5 but I don't understand the byte 01 ? what
> does it mean ?
>
The most significant bit of "8A" simply means there are more bytes coming
along which combined together represent a varint value, and the most
significant bit of "01" suggests this is the last byte of the varint. So
you combine the two to decode the varint value:
8A 01 ==> (1)000 1010 (0)000 0001 == remove the most significant bit and
swap the position for it's little endian ==> 000 0001 000 1010 ==> wire
type 2, tag 17
See the varint encoding:
https://developers.google.com/protocol-buffers/docs/encoding


>
> Thanks for your help
>
>  --
> 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/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.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to