使用JavaScript处理协议缓冲区中的任何

发布于 2025-01-24 03:16:45 字数 539 浏览 3 评论 0原文

我正在尝试在包装协议缓冲区(使用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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文