使用JavaScript处理协议缓冲区中的任何
我正在尝试在包装协议缓冲区(使用nodejs)中处理一些通用消息值:
message MessageWrapper {
string id = 1;
google.protobuf.Any wrapped_message = 2;
....
}
作为其中的一部分,我必须打包()any:
const wrapper = new MessageWrapper();
const wrappedMessage = new Any();
wrappedMessage.pack(msg.serializeBinary(), msgType);
问题的核心是msgtype。如果我使用的是Java,我可以获得msg.getDescriptorfortype(),但是JavaScript似乎并不支持它..自我描述级别。除了手动提供字符串类型URL之外,如何获得它?
附录:说实话,我不确定Pack()的MSGTYPE是用什么。看来我可以将任何字符串值放在其中,包装和解开包装似乎可以正常工作。这是什么用的?
I'm trying to handle some generic Message values within a wrapping protocol buffer (with nodejs):
message MessageWrapper {
string id = 1;
google.protobuf.Any wrapped_message = 2;
....
}
as part of this, I have to pack() the Any:
const wrapper = new MessageWrapper();
const wrappedMessage = new Any();
wrappedMessage.pack(msg.serializeBinary(), msgType);
The heart of the problem is the msgType. If I was using java, I could get the msg.getDescriptorForType(), but javascript doesn't seem to support that.. level of self description. Outside of manually supplying the string type url, how does one get it?
Addendum: To be honest I'm not sure what the msgType of pack() is used for. It seems I can put any string value in there and packing and unpacking seem to work fine. What's it for?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论