diff options
author | Christian Höppner <hoeppi@google.com> | 2023-01-31 10:54:20 +0100 |
---|---|---|
committer | Christian Höppner <hoeppi@google.com> | 2023-02-07 08:52:30 +0000 |
commit | e831c33179b55b753630e0555cdc32b83b81e954 (patch) | |
tree | 17248d9d03bf489f8d6a547d8953286d78edc65a | |
parent | 358fe40267afd0cb5380d132cc93ddcbed2beb44 (diff) | |
download | golang-protobuf-e831c33179b55b753630e0555cdc32b83b81e954.tar.gz |
proto: document Equal behavior of invalid messages
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>
-rw-r--r-- | proto/equal.go | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/proto/equal.go b/proto/equal.go index baa1bc19..1a0be1b0 100644 --- a/proto/equal.go +++ b/proto/equal.go @@ -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 |