我有下面的协议缓冲区。请注意,StockStatic是一个重复的字段。谷歌协议缓冲区重复字段C++
message ServiceResponse
{
enum Type
{
REQUEST_FAILED = 1;
STOCK_STATIC_SNAPSHOT = 2;
}
message StockStaticSnapshot
{
repeated StockStatic stock_static = 1;
}
required Type type = 1;
optional StockStaticSnapshot stock_static_snapshot = 2;
}
message StockStatic
{
optional string sector = 1;
optional string subsector = 2;
}
我在填充StockStatic字段的同时遍历一个向量。
ServiceResponse.set_type(ServiceResponse_Type_STOCK_STATIC_SNAPSHOT);
ServiceResponse_StockStaticSnapshot stockStaticSnapshot;
for (vector<stockStaticInfo>::iterator it = m_staticStocks.begin(); it!= m_staticStocks.end(); ++it)
{
StockStatic* pStockStaticEntity = stockStaticSnapshot.add_stock_static();
SetStockStaticProtoFields(*it, pStockStaticEntity); // sets sector and subsector field to pStockStaticEntity by reading the fields using (*it)
}
但上面的代码是正确的只有StockStatic是一个可选字段,而不是重复栏。我的问题是我错过了哪些代码,使它成为重复的字段?
只是好奇,当你重复这个问题时,你面对的问题到底是什么? – VNarasimhaM 2009-11-20 14:59:53