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, –