Skip to content

Commit

Permalink
proto: document Equal behavior of invalid messages
Browse files Browse the repository at this point in the history
The doc comment of proto.Equal now explicitly describes the behavior
in the case when one message is valid and other is invalid.

Change-Id: Ifeba40277c7da25193d46ad496e910f9b63eb795
Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/464275
Reviewed-by: Joseph Tsai <joetsai@digital-static.net>
Reviewed-by: Chressie Himpel <chressie@google.com>
  • Loading branch information
hoeppi-google committed Feb 7, 2023
1 parent 358fe40 commit e831c33
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions proto/equal.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,13 @@ import (
// - Maps are equal if they have the same set of keys and
// the corresponding value for each key is equal.
//
// If two messages marshal to the same bytes under deterministic serialization,
// then Equal is guaranteed to report true.
// An invalid message is not equal to a valid message.
// An invalid message is only equal to another invalid message of the
// same type. An invalid message often corresponds to a nil pointer
// of the concrete message type. For example, (*pb.M)(nil) is not equal
// to &pb.M{}.
// If two valid messages marshal to the same bytes under deterministic
// serialization, then Equal is guaranteed to report true.
func Equal(x, y Message) bool {
if x == nil || y == nil {
return x == nil && y == nil
Expand Down

0 comments on commit e831c33

Please sign in to comment.