golang / protobuf

Go support for Google's protocol buffers
BSD 3-Clause "New" or "Revised" License
9.73k stars 1.58k forks source link

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

Open kevinburke1 opened 4 years ago

kevinburke1 commented 4 years ago

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 commented 4 years ago

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

dsnet commented 4 years ago

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?

kevinburke1 commented 4 years ago

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

kevinburke1 commented 4 years ago

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

dsnet commented 4 years ago

whether utility functions like ptypes.TimestampProto are being migrated.

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

shaunco commented 4 years ago

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.

dsnet commented 4 years ago

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.

Apologiz commented 4 years ago

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.

dsnet commented 4 years ago

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.

Apologiz commented 4 years ago

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