Just to make this more concrete let's assume we're working with a message
like this:

syntax = "proto2";

message MyMessage {
  optional fixed64 a = 16;
  optional int32 b = 30;
};

I think the problem is that varints are encoded with the least-significant
7-bit groups first, and you got the order backwards. This worked by
coincidence for the first field but not for the second. So interpreting the
second field (field number 30) should go like this:

F0 01 -> 1111 0000 0000 0001

Strip off the leading bit from each byte, since those just tell us how far
to keep reading the varint:

111 0000 000 0001

Flip these two 7-bit groups since the least-significant comes first on the
wire:

000 0001 111 0000

Strip off the last 3 bits, which represent the wire type 0 for varint:

000 0001 111 0

Converting this to decimal we finally have our result of 30.

On Tue, Sep 27, 2016 at 12:41 AM, <yanxi9...@gmail.com> wrote:

> where can i see about encoding rule about  field_number, in
> https://developers.google.com/protocol-buffers/docs/encoding is too simple
>
> fixed64 a = 16
> varint b = 30
>
> 81 01 00 00 00 00 00 00 F0 BF F0 01 00
>
> 81 01 -> 1000 0001 0000 0001 -> 000 0001 000 0 -> 16
> F0 01 -> 1111  0001 0000 0001 -> 111 0001 000 0 -> 1808
>
> where i am wrong ?
>
> --
> 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 https://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 https://groups.google.com/group/protobuf.
For more options, visit https://groups.google.com/d/optout.

Reply via email to