void demo_csgo::handle_netmessages(google::protobuf::io::CodedInputStream& cis) { if(this->netmessage_callbacks[msg_type].empty()) { cis.Skip(cis.BytesUntilLimit()); return; } T msg; if(!msg.MergeFromCodedStream(&cis)) { std::cerr << "handle_netmessages<" << typeid(T).name() << ">(): !msg.MergeFromCodedStream(&cis)" << std::endl; return; } for(auto f : this->netmessage_callbacks[msg_type]) { f(&msg); } }
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; } }