我有下面的協議緩衝區。請注意,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