Skip to content

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

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

Open
kevinburke1 opened this issue Apr 12, 2020 · 10 comments

Comments

@kevinburke1
Copy link

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
Copy link
Author

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

@dsnet
Copy link
Member

dsnet commented Apr 12, 2020

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
Copy link
Author

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

@kevinburke1
Copy link
Author

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

@dsnet
Copy link
Member

dsnet commented Apr 12, 2020

whether utility functions like ptypes.TimestampProto are being migrated.

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

@dsnet dsnet changed the title Upgrade guide devsite: add github.com/golang/protobuf to google.golang.org/protobuf migration guide Apr 13, 2020
@shaunco
Copy link

shaunco commented Apr 23, 2020

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
Copy link
Member

dsnet commented Apr 23, 2020

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
Copy link

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
Copy link
Member

dsnet commented May 13, 2020

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
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants