我如何知道在使用 Protocol Buffers 库时收到了什么消息?

发布于 2024-10-01 13:16:55 字数 410 浏览 0 评论 0原文

看来我不了解协议缓冲区的一些简单内容,但这对我和我的实际用例来说都是非常重要的问题。

在阅读有关协议缓冲区的文档时,我不明白如何知道应该从流中解码哪条消息?所有关于某些已定义消息的示例,但如果您定义了几个完全不同的消息并且您想要在两个进程之间发送这些消息 - 您如何知道您刚刚收到了哪条消息?

或者协议缓冲区可能不会尝试解决这个问题并将这个问题留给另一个抽象级别?

或者也许我应该将消息打包成这样的结构:

message wrapper {
   required string message_name = 1;
   string packed_message = 2; 
}

然后我应该分两个阶段解码消息:首先获取 message_name,然后在第二阶段解码真正的打包消息,不是吗?

It seems I don't understand something simple about Protocol Buffers, but this is very important question for me and for my real use-case.

While reading documentation about Protocol Buffers I don't understand how one know which message you should decode from the stream? All examples about some defined Message, but if you have defined several completelly different messages and you want to send those messages between 2 processes -- how do you know which message you have just received?

Or maybe Protocol Buffers do not try to address this problem and leave this question for another abstraction level?

Or maybe I should pack the message into structure like that:

message wrapper {
   required string message_name = 1;
   string packed_message = 2; 
}

And then I should decode message in 2 stages: get the message_name at first, and then decode real packed message at second stage, should not I?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文