如何在C++中填充重复的自定义协议缓冲区字段?
协议缓冲区示例:
package protocol;
import "enumerations.proto";
option optimize_for=SPEED;
message UserCommandProtocol {
required uint64 utcTime=1;
required uint64 playerId=2;
optional int32 targetId=3;
optional int32 number=4;
message pair {
required float first = 1;
required float second = 2;
}
repeated uint64 bucketId=5 [packed=true];
repeated pair points=6;
repeated pair backupPoints=7;
required COMMANDS command=8;
optional Type type=9;
optional Orientation orientation=10;
optional COMMANDS_PRIORITY priority=11;
}我只对填充点有问题。在我的代码中,我有一个对象std::list<std::pair<float,float>> p,我想将这些值复制到UserCommandProtocol points。
发布于 2012-12-09 20:10:13
迭代您的对列表,添加它们中的每一个。
UserCommandProtocol user_command;
// then, iterate over the list... for each element of the list do:
std::list<std::pair<float,float>>::iterator it = ...;
pair* added_pair = user_command.add_points();
added_pair->set_first(it->first);
added_pair->set_second(it->second);您可能需要阅读协议缓冲区文档的字段部分(特别是重复嵌入消息字段小节)。
https://stackoverflow.com/questions/13763809
复制相似问题