英文:
marshal protoreflect.MessageDescriptor
问题
我正在尝试使用google.golang.org/grpc/reflection中的代码,将protoreflect.MessageDescriptor进行编组。我的想法是让服务器向客户端提供protoreflect.MessageDescriptor。
客户端将使用protoreflect.MessageDescriptor和dynamicpb.NewMessage来实例化protobuf消息。
我无法对protoreflect.MessageDescriptor进行编组,因为它没有实现ProtoReflect()方法。似乎不可能对其进行编组并在网络上传输。
有人已经尝试过这样做吗?我是否在尝试在Go的GRPC实现中做一些被设计禁止的事情?
英文:
I am trying, in the line of google.golang.org/grpc/reflection to marshall a protoreflect.MessageDescriptor. The idea is to have a server serving protoreflect.MessageDescriptor to a client.
The client would use the protoreflect.MessageDescriptor with dynamicpb.NewMessage to instanciate protobuf messages.
I am not able to marshal protoreflect.MessageDescriptor because it does not implement ProtoReflect(). It does not seem to be possible to marshall it and "send" it on the wire.
Anyone has tried that already? Am I trying to do something forbidden by design in the go implementation of GRPC?
答案1
得分: 1
我相信你想在你的协议中使用DescriptorProto,而不是protoreflect.MessageDescriptor。在protodesc包中有一些转换函数,比如:https://pkg.go.dev/google.golang.org/protobuf/reflect/protodesc#ToDescriptorProto
英文:
I believe you want to be using DescriptorProto in your protocol, not a protoreflect.MessageDescriptor. There are conversion functions in the protodesc package like: https://pkg.go.dev/google.golang.org/protobuf/reflect/protodesc#ToDescriptorProto
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。


评论