0
私はこれを正しく行っているかどうかは完全にはわかりません。 MergeとParseFromCodedStreamの両方を試した場合。以下のコードを出力:Protofuf C++ - 逆シリアル化されたメッセージにデータがありません
bool tcp_connection::readDelimitedFrom(
google::protobuf::io::ZeroCopyInputStream* rawInput,
jvm* message, uint32_t* payloadSize) {
DEBUG && (cerr << "------ readDelimitedFrom.begin " << '\n');
// We create a new coded stream for each message. Don't worry, this is fast,
// and it makes sure the 64MB total size limit is imposed per-message rather
// than on the whole stream. (See the CodedInputStream interface for more
// info on this limit.)
google::protobuf::io::CodedInputStream input(rawInput);
// Read the size.
if (!input.ReadLittleEndian32(payloadSize)) return false;
DEBUG && (cerr << "------ readDelimitedFrom got size: " << *payloadSize << '\n');
DEBUG && (cerr << "------ input.CurrentPosition: " << input.CurrentPosition() << '\n');
DEBUG && (cerr << "------ " << '\n');
try {
google::protobuf::io::CodedInputStream::Limit limit =
input.PushLimit(*payloadSize);
DEBUG && (cerr << "------ PushLimit:" << *payloadSize << '\n');
// Parse the message.
if (!message->ParseFromCodedStream(&input)) return false;
DEBUG && (cerr << "------ MergeFromCodedStream" << '\n');
cout << "----------- size:" << message->ByteSize() << endl;
if (!input.ConsumedEntireMessage()) return false;
DEBUG && (cerr << "------ ConsumedEntireMessage" << '\n');
// Release the limit.
input.PopLimit(limit);
DEBUG && (cerr << "------ PopLimit" << '\n');
}
catch (const std::exception &exc)
{
// catch anything thrown within try block that derives from std::exception
cerr << exc.what() << endl;
return false;
}
// Tell the stream not to read beyond that size.
DEBUG && (cerr << "------ readDelimitedFrom return true " << '\n');
return true;
}
コンソールアウト:
---- connection.start (disabling Nagle)
------ h.r.h 4 bytes
------ readDelimitedFrom.begin
------ readDelimitedFrom got size: 76
------ input.CurrentPosition: 4
------
------ PushLimit:76
------ MergeFromCodedStream
----------- size:0
------ ConsumedEntireMessage
------ PopLimit
------ readDelimitedFrom return true
は、あなたはまた、あなたが 'rawInput'を入手できます方法を示しすることはできますか? – Ptaq666
boost :: asio :: async_read(socket()、mutable_buffers_1、 –