问题描述
在阅读了protobuf支持动态创建动态消息之后,我试图创建一个返回动态消息的gRPC服务.(例如,在数据库中返回一行但仅在运行时才知道该模式的服务)
After reading that protobuf supports creation of dynamic messages on the fly, I am trying to create a gRPC service that returns a dynamic message. (e.g. a service that returns a row in database but the schema is only known at run time)
有可能吗,我该如何构造.proto?
Is it possible and how would I construct the .proto for that?
谢谢.
推荐答案
在Java中,有一个名为 DynamicMessage ,该描述符可以接收并发送一个描述符.如果可以在运行时获取描述符,则可以通过这种方式获取.
In Java there is a special object called DynamicMessage which can take a descriptor and send that. If you can get the descriptor at runtime you can get it that way.
虽然不完全符合proto的精神,但是您可以使用 struct.proto .
Also, while not exactly in the spirit of proto, you can represent arbitrary structured data using struct.proto.
这篇关于使用动态消息作为参数的gRPC的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!