我如何知道在使用 Protocol Buffers 库时收到了什么消息?
看来我不了解协议缓冲区的一些简单内容,但这对我和我的实际用例来说都是非常重要的问题。
在阅读有关协议缓冲区的文档时,我不明白如何知道应该从流中解码哪条消息?所有关于某些已定义消息的示例,但如果您定义了几个完全不同的消息并且您想要在两个进程之间发送这些消息 - 您如何知道您刚刚收到了哪条消息?
或者协议缓冲区可能不会尝试解决这个问题并将这个问题留给另一个抽象级别?
或者也许我应该将消息打包成这样的结构:
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
请参阅自我描述消息部分
Look at self describing messages section