On Tue, Sep 29, 2009 at 12:41 PM, alopecoid <[email protected]> wrote:
> But, as in my example, that doesn't seem to be the case (necessarily). > Again, for example, let's say you have two messages, both of the same > type. The proto defines two optional fields, both of type variable > int64. > > Say message A poopulates both optional fields: > [1 byte tag] [3 byte value] [1 byte tag] [2 byte value] = 7 bytes > > And message B populates only one optional field: > [1 byte tag] [6 byte value] = 7 bytes > > Couldn't these generate, by chance, the same 7 bytes? No. > Yes, using > deserialize will correctly parse two unequal messages, but if you look > at the raw serialized byte sequences, they could actually be the same. > That makes no sense. If the bytes were the same, how would deserializing them be able to produce unequal messages? If you must know the details, in the varint encoding, the upper bit of each byte is used to indicate whether there are more bytes in the value. So, in a 3-byte varint, the first two bytes have the upper bit set, but the last byte does not. So obviously a 3-byte varint cannot start with the same bytes as a 6-byte varint, because in a 6-byte varint the third byte would have the upper bit set. However, these details really aren't necessary to answer the question. The same bytes, passed to the same parsing function, will produce the same output, regardless of how the encoding works. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
