아래 프로토콜 버퍼가 있습니다. StockStatic은 반복 필드입니다.Google 프로토콜 버퍼 반복 필드 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