On Sun, Feb 28, 2010 at 3:47 AM, adamdms <[email protected]>wrote:
> I created (from tutorial example) below message. > > Person ID: 1 > Name: Adam > E-mail address: [email protected] > Home phone #: 12345 > Mobile phone #: 9999 > Person ID: 2 > Name: Honorata > E-mail address: [email protected] > Work phone #: 44444 > Home phone #: 22222 > Person ID: 3 > Name: Przemek > E-mail address: przemek©[email protected] > Home phone #: 555555 > > It was encoded as: > 0A 2E 0A 04 41 64 61 6D 10 01 1A 0F 61 64 61 6D 64 6D 73 40 74 6C 65 > 6E 2E 70 6C 22 09 0A 05 31 32 33 34 35 10 01 22 08 0A 04 39 39 39 39 > 10 00 0A 30 0A 08 48 6F 6E 6F 72 61 74 61 10 02 1A 0C 68 6F 6E 63 69 > 6B 40 77 70 2E 70 6C 22 09 0A 05 34 34 34 34 34 10 02 22 09 0A 05 32 > 32 32 32 32 10 01 0A 2D 0A 07 50 72 7A 65 6D 65 6B 10 03 1A 14 70 72 > 7A 65 6D 65 6B C2 A9 63 6F 73 40 74 6C 65 6E 2E 70 6C 22 0A 0A 06 35 > 35 35 35 35 35 10 01 > > I don't understand that encoding! > 0A - 0|000 1010 - wire type 0 (variant); field number 1 (but in .proto > field "Person ID" has number 2) > This is field number 1, wire type 2 (length-delimited). Remember that the thing you are encoding is an AddressBook, not a Person. message AddressBook { repeated Person person = 1; } So the first byte is the tag for a person in the AddressBook. > 2E - 0|010 1110 - 46 (but first person has ID = 1) > This is the length of the Person message. > 0A - 0|000 1010 - wire type 0 (variant, but that field is string, it > should be type = 2); field number 1 (it is ok) > Now we're actually in the Person, so this is the "name" field. Note that fields are ordered by field number, so "name" always comes *before* "id". > 04 - length is ok > 41 - "A" > 64 - "d" > 61 - "a" > 6D - "m" > ... > > Can someone explain this to me? > > -- > You received this message because you are subscribed to the Google Groups > "Protocol Buffers" group. > To post to this group, send email to [email protected]. > To unsubscribe from this group, send email to > [email protected]<protobuf%[email protected]> > . > 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 [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/protobuf?hl=en.
