Sponge
CS144's user-space TCP library
|
A class that assembles a series of excerpts from a byte stream (possibly out of order, possibly overlapping) into an in-order byte stream. More...
#include <stream_reassembler.hh>
Public Member Functions | |
StreamReassembler (const size_t capacity) | |
Construct a StreamReassembler that will store up to capacity bytes. More... | |
bool | empty () const |
Is the internal state empty (other than the output stream)? More... | |
void | push_substring (const std::string &data, const uint64_t index, const bool eof) |
Receive a substring and write any newly contiguous bytes into the stream. More... | |
size_t | unassembled_bytes () const |
Access the reassembled byte stream | |
const ByteStream & | stream_out () const |
ByteStream & | stream_out () |
Private Attributes | |
size_t | _capacity |
The maximum number of bytes. More... | |
ByteStream | _output |
The reassembled in-order byte stream. More... | |
A class that assembles a series of excerpts from a byte stream (possibly out of order, possibly overlapping) into an in-order byte stream.
Definition at line 11 of file stream_reassembler.hh.
StreamReassembler::StreamReassembler | ( | const size_t | capacity | ) |
Construct a StreamReassembler
that will store up to capacity
bytes.
Definition at line 15 of file stream_reassembler.cc.
bool StreamReassembler::empty | ( | ) | const |
Is the internal state empty (other than the output stream)?
true
if no substrings are waiting to be assembled Definition at line 26 of file stream_reassembler.cc.
void StreamReassembler::push_substring | ( | const std::string & | data, |
const uint64_t | index, | ||
const bool | eof | ||
) |
Receive a substring and write any newly contiguous bytes into the stream.
The StreamReassembler will stay within the memory limits of the capacity
. Bytes that would exceed the capacity are silently discarded.
data | the substring |
index | indicates the index (place in sequence) of the first byte in data |
eof | the last byte of data will be the last byte in the entire stream |
This function accepts a substring (aka a segment) of bytes, possibly out-of-order, from the logical stream, and assembles any newly contiguous substrings and writes them into the output stream in order.
Definition at line 20 of file stream_reassembler.cc.
|
inline |
Definition at line 37 of file stream_reassembler.hh.
|
inline |
Definition at line 36 of file stream_reassembler.hh.
size_t StreamReassembler::unassembled_bytes | ( | ) | const |
The number of bytes in the substrings stored but not yet reassembled
Definition at line 24 of file stream_reassembler.cc.
|
private |
The maximum number of bytes.
Definition at line 16 of file stream_reassembler.hh.
|
private |
The reassembled in-order byte stream.
Definition at line 15 of file stream_reassembler.hh.