2012-02-07 8 views
0

をいるProtobufするバイナリストリームを割り当て、私は、次のprotocファイルがあります。C++ Googleのプロトコルバッファ:オブジェクト

message DataChunk{ 
    required bool isHash=1; 
    required int64 hash=2; 
    required string data=3; 
} 

message responseBody{ 
    repeated DataChunk dataChunk=1; 
} 

をそして、私は、次のC++の機能を持っている:

void eamorr(string data){ //data is a protocol buffer stream converted to a string 
    responseBody rb; 

    rb=some_function_of(data); //what to do here? 
} 

文字列 "データ" が作成されました

... 
std::ostringstream stream; 
rb.SerializeToOstream(&stream); 
string protobufStream = stream.str(); 
... 

私の質問は、どのように私はメンバー要素にアクセスできるように文字列をprotocオブジェクトに変換するのですか?私はC++にはとても新しいことを覚えておいてください。

答えて

1

あなたはそのための

rb.ParseFromString(data) 
+0

ご挨拶、ありがとうございます。それは今働いている。遅れて返信して申し訳ありません。 – Eamorr

2

しない理由オブジェクトデータを作成する:

responseBody rb; //this is your proto object; 
rb.SerializeToString(&data); 

を次にデシリアライズに:

void eamorr(string data){ 
    responseBody rb; 
    rb.ParseFromString(data); 
} 
+0

感謝を使用することができます - それは今働いています。 – Eamorr

関連する問題