diff --git a/src/reassembler.cc b/src/reassembler.cc index ededa6f..f47f162 100644 --- a/src/reassembler.cc +++ b/src/reassembler.cc @@ -5,11 +5,55 @@ using namespace std; void Reassembler::insert(uint64_t first_index, string data, bool is_last_substring, Writer &output) { - if (first_index > nxt_idx + output.available_capacity()) - return; - if (is_last_substring) { - if (i) + uint64_t cap = output.available_capacity(); + uint64_t max_idx = nxt_idx+cap; + uint64_t dst_idx = first_index+data.size(); + if(first_index>max_idx) return; + if(is_last_substring) end_idx=dst_idx>max_idx?max_idx:dst_idx; + if(first_index==nxt_idx){ + if(capnxt_idx){ + if(first_index+data.size()>max_idx){ + store(first_index,data.substr(0,max_idx-first_index)); + end_idx=max_idx; + } + else store(first_index,data); + } + else{ + if(first_index+data.size()>=max_idx){ + output.push(data.substr(nxt_idx-first_index,cap)); + output.close(); + } + else{ + output.push(data.substr(nxt_idx-first_index,data.size()-nxt_idx+first_index)); + nxt_idx+=data.size()-nxt_idx+first_index; + backteam(output); + } + } +} + +void Reassembler::store(uint64_t idx,std::string str){ + //需要处理以下,避免内部重叠 + for(auto it=data_map.begin();it!=data_map.end();it++){ + //此处处理掉内部的重叠问题 } + data_map[idx]=str; } +void Reassembler::backteam(Writer& out) { + for(auto it=data_map.begin();it!=data_map.end();it++){ + if(it->first==nxt_idx){ + + } + } +} uint64_t Reassembler::bytes_pending() const { return {}; } diff --git a/src/reassembler.hh b/src/reassembler.hh index 4d8466b..237fa53 100644 --- a/src/reassembler.hh +++ b/src/reassembler.hh @@ -40,4 +40,6 @@ class Reassembler { uint64_t nxt_idx; uint64_t end_idx; std::map data_map; + void store(uint64_t,std::string); + void backteam(Writer&); };