protobuf
protobuf copied to clipboard
devsite: add github.com/golang/protobuf to google.golang.org/protobuf migration guide
Is there a document anywhere that describes how to upgrade a v1 project to a v2 project? There is a blog post, however it isn't comprehensive. I tried searching both in this repository and in https://github.com/protocolbuffers/protobuf-go.
Currently, I'm running into this error, and I'm unsure how to resolve it. (I can open this specific instance as a separate issue. However, were an upgrade guide to exist, I presume that it would describe how to address the problem I'm running into.)
httputil/httputil.go:18:24: cannot use &pb.Empty literal (type *pb.Empty) as type protoreflect.ProtoMessage in argument to Respond:
*pb.Empty does not implement protoreflect.ProtoMessage (missing ProtoReflect method)
I am attempting to regenerate protobuf files using the new protoc-gen-go however the generated file is identical to the old file so I'm unsure what I'm missing.
Ah, the new file is being written to a different location. I'll open another ticket.
That's an odd error. Is pb.Empty the same one as "github.com/golang/protobuf/ptypes/empty".Empty or "google.golang.org/protobuf/types/known/emptypb".Empty?
No it's a custom struct. I opened a separate ticket for that issue at #1076.
Another issue I hope an upgrade guide would cover is how or whether utility functions like ptypes.TimestampProto are being migrated.
whether utility functions like ptypes.TimestampProto are being migrated.
You'd be interested in https://go-review.googlesource.com/c/protobuf/+/225298
I'd also be interested in a migration document and status on things like ptypes. Switching imports to "google.golang.org/protobuf/proto" was seamless , but protoc-gen-go still generates pb.go files that reference v1 imports, and I don't see any new FileOptions in https://github.com/protocolbuffers/protobuf/blob/master/src/google/protobuf/descriptor.proto or new parameters to protoc-gen-go that would force v2 generation, so my projects all have the v1 and v2 packages in them now. Getting to just v2 packages would be great.
The migration plan for the well-known types is still being worked on. https://go-review.googlesource.com/c/protobuf/+/225298 generates first-class support for well-known types directly into the generated packages.
Colleagues, the ptypes.MarshalAny and ptypes.UnmarshalAny methods did not migrate to google.golang.org/protobuf, but they remained in the example and now it’s not clear how to unmarshal any on a struct.
Colleagues, the ptypes.MarshalAny and ptypes.UnmarshalAny methods did not migrate
You are correct. In the v1.20.0 release notes, there are several portions of the old API that do not yet have an equivalent replacement in the google.golang.org/protobuf module:
Some existing features present in the
github.com/golang/protobufmodule are currently unavailable in this module:
- Manipulation of the wire format: The older module provides functionality for directly manipulating the raw wire format through methods on the
proto.Buffertype.- Helper functions for well-known types: The older module provides the
ptypespackage containing helper functions for interacting with the well-known types such asAnyorTimestampmessages.We plan to add these features to this module in the near future and improve upon them.
A moral replacement for proto.Buffer was released in v1.21.0 with the protopack package. However, helpers for the well-known types are still not migrated and being worked on presently. It is okay to keep using ptypes for the time being.
Thank you, @dsnet! Do you need my help?