void MsgBuf::write(const Msg& msg) { #ifdef FAST_VECTOR MsgBuf::Iterator it = container_.lower_bound(msg, KeyComp(comp_)); #else MsgBuf::Iterator it = lower_bound(container_.begin(), container_.end(), msg, KeyComp(comp_)); #endif if (it == end() || it->key != msg.key) { container_.insert(it, msg); size_ += msg.size(); } else { size_ -= it->size(); it->destroy(); *it = msg; size_ += msg.size(); } }
bool MsgBuf::read_from(BlockReader& reader) { uint32_t cnt = 0; if (!reader.readUInt32(&cnt)) return false; // container_.resize(cnt); // for (size_t i = 0; i < cnt; i++ ) { // if (!container_[i].read_from(reader)) return false; // size_ += container_[i].size(); // } for (size_t i = 0; i < cnt; i++ ) { Msg msg; if (!msg.read_from(reader)) return false; size_ += msg.size(); container_.push_back(msg); } return true; }