Skip to content
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

Starting on apiv2 - custom types #711

Open
turbodonkey opened this issue Dec 1, 2020 · 1 comment
Open

Starting on apiv2 - custom types #711

turbodonkey opened this issue Dec 1, 2020 · 1 comment

Comments

@turbodonkey
Copy link

Hi, I’d like to at a start help to get custom types working in apiv2. Documentation on proto-gen-go code is a little light on for me, so wondering if anyone here can help guide me.

Ideally I’d like to get a working .pb.go file by hand to understand what is needed but even that isn’t as easy as it sounds, as I’m unsure of what’s needed.

Can anyone explain this or point me in the right direction here. Any guidance is appreciated and I can help submit back into apiv2 code if I can get it to work?

@silasdavis
Copy link

silasdavis commented Jan 12, 2021

I think the basic idea would be to generate code for 'custom types' that implements protoreflect.Message (actually they should implement protoreflect.ProtoMessage but this just provides a layer of indirection between the custom type and the protobuf reflective type): https://godoc.org/google.golang.org/protobuf/reflect/protoreflect#Message.

This would be analogous the the various marshalling methods requried by gogoproto.customtype: https://github.com/gogo/protobuf/blob/master/custom_types.md#custom-type-method-signatures.

For types that implement ProtoMessage the protobuf v2 library will use the Message interface to reflect on the type and push/pull values for marshalling. At that point the code you write to implement Message can handle the mapping between the protobuf type system and any arbitrary Go type.

I have been exploring the API myself to see whether there are some types that are open for extension but with which I could share most of the implementation. However, most of the Message implementing types are internal, here is an example: https://github.com/protocolbuffers/protobuf-go/blob/master/testing/protocmp/reflect.go#L39

You can read about the rationale for the protoreflect interfaces here: https://blog.golang.org/protobuf-apiv2. These interfaces are the main content of the v2 API.

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

No branches or pull requests

2 participants