Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add an EqualMessageVT generator #66

Merged
merged 1 commit into from
Jan 27, 2023
Merged

Conversation

misberner
Copy link
Contributor

This PR adds a generator that makes EqualVT accessible with a uniform signature as EqualMessageVT(proto.Message) bool.

The main motivation is to ease migration from Gogo protobuf by offering a drop-in replacement for "github.com/gogo/protobuf/proto".Equal, which uses optimized code where available. With the change in this PR, this can simply be done via

func Equal(a, b proto.Message) bool {
  if aVT, ok := a.(interface{ EqualMessageVT(proto.Message) bool }); ok {
    return aVT.EqualMessageVT(b)
  }
  // we can disregard checking b because if a and b are not of the same type, Equal will be fast anyway
  return proto.Equal(a, b) // from google.golang.org/protobuf/proto
}

I had added a similar facility when adding CloneVT via CloneGenericVT. However, with the launch of generics in go1.18, this naming has not aged well. I therefore adopted ...Message... for the variant accepting a proto.Message, and have also applied this by renaming CloneGenericVT to CloneMessageVT (the old variant is still generated for backwards-compatibility, but marked deprecated).

@vmg
Copy link
Member

vmg commented Jan 27, 2023

Looks good! Thanks for your contribution! I'm going to push a separate change to remove the deprecation notice from the CloneGenericVT API: since we've never actually released a version of vtprotobuf with that API, we can rename it without having to keep the old version around indefinitely.

@vmg vmg merged commit 9c8bcf0 into planetscale:main Jan 27, 2023
smira added a commit to smira/os-runtime that referenced this pull request Jan 30, 2023
See planetscale/vtprotobuf#66

Instead of using generic `proto.Equal` which is reflection-based, use
generated (when available) vtprotobuf equality check.

Resource equality check is used frequently in Omni to suppress updates
if the resources are equal.

Signed-off-by: Andrey Smirnov <andrey.smirnov@talos-systems.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants