protobuf
protobuf copied to clipboard
Add github.com/golang/protobuf/proto.MessageV2 equivalent to google.golang.org/protobuf
Also we need a protoiface.MessageV1 that is allowed to be referenced by outside packages.
Background: we have an API that accepts v1 proto.Messages as a parameter. We would like to stop importing the old github.com/golang/protobuf since it is deprecated and our users keep complaining about it.
@dsnet suggested the proto team might be interested in adding this in https://github.com/grpc/grpc-go/pull/4330#discussion_r618674125.
@neild what are your thoughts on this?
What would the use case be for a "github.com/golang/protobuf/proto".MessageV2? You can just reference "google.golang.org/protobuf/proto".Message directly. This won't add any new transitive dependencies, since "github.com/golang/protobuf/proto" already depends on "google.golang.org/protobuf/proto".
Defining a public version of MessageV1 somewhere in the "google.golang.org/protobuf" module seems reasonable to me, although I'm not sure what the best place for it would be. A new package? (protocompat? Something under types/?) Maybe we should just say users can reference the one in protoiface if they need it, although that would be unfortunate from an API cleanliness standpoint.
If gRPC wants to refer to protoiface.MessageV1 directly while this is being worked out, that package does have a stable API.
What would the use case be for a "github.com/golang/protobuf/proto".MessageV2? You can just reference "google.golang.org/protobuf/proto".Message directly.
github.com/golang/protobuf/proto.MessageV2 is a conversion function that turns a proto v1 message into a proto v2 message.
The goal here is to stop importing github.com/golang/protobuf/... from anywhere our library, since it is marked as deprecated.
If gRPC wants to refer to protoiface.MessageV1 directly while this is being worked out, that package does have a stable API.
This wording from pkg.go.dev was scary to me:
WARNING: This package should only be imported by message implementations. The functionality found in this package should be accessed through higher-level abstractions provided by the proto package.
I don't think a temporary solution is necessary here as long as there's buy-in for a more permanent option. We can just wait longer to stop referencing the deprecated-but-can-never-be-deleted github.com/golang/protobuf/... packages.
Sorry, I was confusing the MessageV2 function with an alias to the Message type.
It might make sense to add a new package to google.golang.org/protobuf that contains the type conversion functions. I believe the implementations of these functions are all in the new module anyway, so this shouldn't change the module dependency graph. I don't know what the new package would be named; google.golang.org/protoconvert maybe? It's a shame that google.golang.org/runtime/protolegacy took the protolegacy name.
google.golang.org/protobuf/protoadapt?
I also liked the proposed protocompat
It's a shame that
google.golang.org/runtime/protolegacytook theprotolegacyname.
github.com/golang/protobuf/v2/runtime/protolegacy's documentation makes it sound like it's effectively an internal-only package, so I don't personally see any harm in reusing the name for a public-facing package if that's the best name to use here.
Maybe the package name will be easier to choose if we define the symbols it will contain, and see how it will look when used?
package protoadapt / protocompat / protoconvert / protolegacy
type MessageV1 = protoiface.MessageV1
func ToMessageV2(MessageV1 /* or GeneratedMessage to mirror proto.MessageV2()? */) proto.Message
E.g.
func foo(v1 protoadapt.MessageV1) {
v2 := protoadapt.ToMessageV2(v1)
// ...
}
We have an increasing number of users (see new contributed PR to migrate to the newer proto packages https://github.com/grpc/grpc-go/pull/5740) impacted by this. Could this be prioritized?
@dsnet I'm happy to send a change for the same via Gerrit.
Here's the draft change to review.
Is there more needed for grpc/credentials to be upgraded, or is it just the code that @stpabhi has provided in the PR above? If it's just this code, can someone please merge this in.
please, how do I solve this issue:
go: module github.com/golang/protobuf is deprecated: Use the "google.golang.org/protobuf" module instead.
Take a look at https://pkg.go.dev/google.golang.org/protobuf/protoadapt, but you'll need v1.30.0 of the module