-
Notifications
You must be signed in to change notification settings - Fork 175
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
Question: What would be needed in order to create dynamic messages with proto imports #154
Comments
@gabrielerzinger, I am assuming you are getting an error when you try to create the descriptor (not when creating the message), right? IIUC, you are trying to use To make it more concrete, let's assume we have the following situation:
In order to create a descriptor for a, we have to construct descriptors for its dependencies first (in reverse topological order: leaves first). So the following sequence would be necessary for the given example: // for brevity, omitting error handling (but real code should
// always check the error returned)
fdD, _ := desc.CreateFileDescriptor(fileDProto)
fdC, _ := desc.CreateDescriptor(fileCProto, fdD)
fdB, _ := desc.CreateDescriptor(fileBProto)
fdA, _ := desc.CreateDescriptor(fileAProto, fdB, fdC) So as you can see, we had to supply the dependencies in that last call, when creating a descriptor for |
First of all, thank you very much for the quick response. Do you think there is any way I could make it so I could extract the dependencies from [...]
protoReflectTypePointer := proto.MessageType(protoName)
protoReflectType := protoReflectTypePointer.Elem()
protoValue := reflect.New(protoReflectType)
descriptorMethod, ok := protoReflectTypePointer.MethodByName("Descriptor")
descriptorValue := descriptorMethod.Func.Call([]reflect.Value{protoValue})
protoDescriptor := descriptorValue[0].Bytes()
return protoDescriptor If it were possible to get those dependencies from Again, tyvm for the attention |
If you have the fully-qualified name of the message, this should be easy: md, err := desc.LoadMessageDescriptor(msgName) If that isn't working, I suspect the error message is different. The most common issue is when you've compiled your protos (to To resolve, you will need to modify your invocations of |
I've runned some pre-tests and Im almost sure that was the problem! Thank you very much and thank you for the great work with this lib. (This trully should be added to golang/protobuff sometime)! I think we can close this and sorry if it was not appropriate for an issue :) |
Most of the functionality in this repo will become part of the core runtime. Here's a design doc for v2 API for the core protobuf library, and here's the in-progress work.
No worries! |
First of all, thank you very much for your work on this lib. It's trully awesome and definitely something that is missing on Go. Given that, i've been struggling with the following task: how can i make dynamic messages from protos that import other protos?
Lets say i have Proto A, which imports Proto b in its file, i've already seen that simply trying to use the proto descriptor of A isn't enough, since it says
not enough dependencies
, so I wanted to know, is it already supported to - somehow - use descriptors to create dyn. messages of protos with import? And if not, what could I study in order to do so?Again, thank you very much, this repo is awesome!
The text was updated successfully, but these errors were encountered: