Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Message from discussion Can serialized messages be used reliably as keys?
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Kenton Varda  
View profile  
 More options Sep 29 2009, 3:59 pm
From: Kenton Varda <ken...@google.com>
Date: Tue, 29 Sep 2009 12:59:03 -0700
Local: Tues, Sep 29 2009 3:59 pm
Subject: Re: Can serialized messages be used reliably as keys?

On Tue, Sep 29, 2009 at 12:22 PM, alopecoid <alopec...@gmail.com> wrote:

> Hi,

> 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?)

Only if:

1) The implementation you are using writes fields in canonical order.  All
official implementations do this, and probably most unofficial ones.
 However, implementations are technically allowed to write fields in any
order.

2) There are no unknown fields in the message.  Your message may have
unknown fields if you originally parsed it off the wire and the sender is a
newer binary that knows about new fields recently added to the .proto file.
 In C++ you can get rid of all unknown fields in a message by calling the
DiscardUnknownFields() method.

If possible, I would recommend designing your application such that it only
requires that equal messages have the same serialization *most* of the time.
 For example, if you were designing a cache where the cache key is the hash
of a serialized message, then the worst that can happen if two equal
messages had different serializations is that you'd perform the same
operation twice rather than hitting cache.  As long as this is relatively
rare, it's no big deal.

> - Two unequal messages will always generate unequal byte sequences?

As Jon said, this clearly has to be true.  If two messages could have the
same serialization, then how would the parser know which one to produce when
parsing?

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.