marshal protoreflect.MessageDescriptor可以翻译为”编组 protoreflect.MessageDescriptor”。

huangapple go评论76阅读模式
英文:

marshal protoreflect.MessageDescriptor

问题

我正在尝试使用google.golang.org/grpc/reflection中的代码,将protoreflect.MessageDescriptor进行编组。我的想法是让服务器向客户端提供protoreflect.MessageDescriptor

客户端将使用protoreflect.MessageDescriptordynamicpb.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

huangapple
  • 本文由 发表于 2022年8月24日 22:54:51
  • 转载请务必保留本文链接:https://go.coder-hub.com/73475372.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定