protobuf icon indicating copy to clipboard operation
protobuf copied to clipboard

devsite: add github.com/golang/protobuf to google.golang.org/protobuf migration guide

Open kevinburke1 opened this issue 5 years ago • 10 comments

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.

kevinburke1 avatar Apr 12 '20 03:04 kevinburke1

Ah, the new file is being written to a different location. I'll open another ticket.

kevinburke1 avatar Apr 12 '20 03:04 kevinburke1

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?

dsnet avatar Apr 12 '20 03:04 dsnet

No it's a custom struct. I opened a separate ticket for that issue at #1076.

kevinburke1 avatar Apr 12 '20 04:04 kevinburke1

Another issue I hope an upgrade guide would cover is how or whether utility functions like ptypes.TimestampProto are being migrated.

kevinburke1 avatar Apr 12 '20 05:04 kevinburke1

whether utility functions like ptypes.TimestampProto are being migrated.

You'd be interested in https://go-review.googlesource.com/c/protobuf/+/225298

dsnet avatar Apr 12 '20 05:04 dsnet

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.

shaunco avatar Apr 23 '20 17:04 shaunco

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.

dsnet avatar Apr 23 '20 18:04 dsnet

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.

Apologiz avatar May 13 '20 09:05 Apologiz

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/protobuf module 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.Buffer type.
  • Helper functions for well-known types: The older module provides the ptypes package containing helper functions for interacting with the well-known types such as Any or Timestamp messages.

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.

dsnet avatar May 13 '20 17:05 dsnet

Thank you, @dsnet! Do you need my help?

Apologiz avatar May 13 '20 22:05 Apologiz