bool Connection::dequeue(MessageType type, ::google::protobuf::io::CodedInputStream &stream) { bool res; T msg; uint32_t length; if (!stream.ReadVarint32(&length)) return false; uint32_t bytesLeft = stream.BytesUntilLimit(); if (length > bytesLeft) return false; ::google::protobuf::io::CodedInputStream::Limit limit = stream.PushLimit(length); if ((res = msg.MergePartialFromCodedStream(&stream))) { message(type, msg); } stream.PopLimit(limit); return res; }
bool read_ack( Ack ack, google::protobuf::io::CodedInputStream& codedInput ){ //TODO: use exception. unsigned int ack_size; codedInput.ReadVarint32( &ack_size ); cout<<"ack size recorded as "<< ack_size << endl ; int limit = codedInput.PushLimit( ack_size ); bool ack_parse_ret = ack.ParseFromCodedStream(&codedInput); codedInput.PopLimit( limit ); if( false == ack_parse_ret ){ cerr<<"parse response error" <<endl; return false; } if(not ack.success()){ return false; } else{ return true; } }