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

serializing protoreflect.Message without Go type information? #840

Closed
vadimsht opened this issue Apr 26, 2019 · 2 comments
Closed

serializing protoreflect.Message without Go type information? #840

vadimsht opened this issue Apr 26, 2019 · 2 comments

Comments

@vadimsht
Copy link

I have a go program that implements a domain specific language which supports protos. My goal is to use protoc to generate serialized FileDescriptorSet, feed them (in runtime!) to my go program, and use the type information there to dynamically construct proto objects when executing the DSL script.

So far it is all easy, FileDescriptorSet contains all required information.

But as a final step, I want to serialize thus constructed protos, and I don't want to reimplement all serialization code. Looking at the current v2 API, it is almost, but not quite, possible.

My expectations after reading the design doc is that I can reuse all serialization logic as long as I can provide my own implementation of protoreflect.Message interface (and all dependent "value" interfaces).

In practice, protoreflect.Message has Type() MessageType field, and the only way to construct instances of MessageType is through internal/prototype (since MessageType inherits from Descriptor which has doNotImplement).

So it appears, there's no way to construct proto message types "on the fly": protoreflect.Message can represent only messages generated by protoc and embedded into the go binary.

This surprised me, since if this is the intended behavior, all this proto reflection stuff is no more than a (huge) layer of sugar on top of type information already available in v1 API (via Go reflections and descriptor sets).

Will there be a way to write "polyglot" go programs that can manipulate arbitrary proto messages given their MessageDescriptors?

@dsnet
Copy link
Member

dsnet commented Apr 26, 2019

What you want seems to be #199, which is a feature planned for v2.

Regarding internal/prototype being a private package, that used to be public, but we weren't happy with the API, so we internalized it. The final release will provide users the ability to construct protoreflect.MessageType implementations. The exact API is to be determined.

@vadimsht
Copy link
Author

👍

Thanks for clarifying that the current state is temporary :) I'm waiting eagerly the official v2 release.

@dsnet dsnet changed the title APIv2: Serializing protoreflect.Message without Go type information? serializing protoreflect.Message without Go type information? Mar 4, 2020
@golang golang locked and limited conversation to collaborators Sep 4, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants