On Sep 29, 8:22 pm, alopecoid <alopec...@gmail.com> wrote:
> Can serialized messages be used reliably as keys?
>
> In other words, is it guaranteed that...
>
> - Two equal messages will always generate equal byte sequences?
> (Are fields always written in the same order?)
>
> - Two unequal messages will always generate unequal byte sequences?
> (Are tag identifiers enough to delimit variable length fields from
> accidentally producing equal byte sequences?)
>
> I have a feeling that the answer is no. For example, given a proto
> with two fields, both variable length int64 types, it seems that two
> unequal messages could, by chance, generate the same byte sequence:
>
> [1 byte tag] [3 byte value] [1 byte tag] [2 byte value] = 7 bytes
> [1 byte tag] [2 byte value] [1 byte tag] [3 byte value] = 7 bytes
> [1 byte tag] [6 byte value] = 7 bytes
> ... etc.
>
> If those 7 bytes just happen to be equal, then the serialized messages
> can NOT be used reliably as keys.

Given that the serialized bytes have to be able to *deserialize* back
to the original messages, surely if those original messages aren't
equal, the serialized forms would have to be different too - assuming
we're talking about the same message type. (Two messages of different
types could serialize to the same data, admittedly.)

The Java serialized form does serialize all the fields in order, I
believe.

Jon

--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to