gpt4 book ai didi

c++ - 在消息中包装数据的开销

转载 作者:行者123 更新时间:2023-11-28 04:53:57 26 4
gpt4 key购买 nike

将 protobuf 参数包装在单独的消息中会产生任何额外的运行时开销吗?

这个:

message MyData {
optional uint32 data = 1;
}

message Container {
optional MyData data = 1;
}

对比

message Container {
optional uint32 data = 1;
}

如果重要的话,我只会使用 C++ 实现。

额外的电线开销?序列化开销?访问开销?

最佳答案

根据 encoding explanation of protobufs,每个嵌入式消息都有开销

下面带有一个 int 值的简单消息将被编码为 08 96 01

message Test1 {
required int32 a = 1;
}

同时使用嵌入式消息对消息定义进行编码看起来像 1a 03 08 96 01

Test1:  
message Test3 {
required Test1 c = 3;
}

文档解释说

the last three bytes are exactly the same as our first example (08 96 01), and they're preceded by the number 3 – embedded messages are treated in exactly the same way as strings (wire type = 2).

所以简而言之,1a 03 作为开销添加到 Test3 中,因为 Test1 是另一种消息类型

关于c++ - 在消息中包装数据的开销,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47587467/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com