Sponge
CS144's user-space TCP library
Public Member Functions | Private Attributes | List of all members
BufferList Class Reference

A reference-counted discontiguous string that can discard bytes from the front. More...

#include <buffer.hh>

Public Member Functions

void append (const BufferList &other)
 Append a BufferList. More...
 
const std::deque< Buffer > & buffers () const
 Access the underlying queue of Buffers. More...
 
std::string concatenate () const
 Make a copy to a new std::string. More...
 
 operator Buffer () const
 Transform to a Buffer. More...
 
void remove_prefix (size_t n)
 Discard the first n bytes of the string (does not require a copy or move) More...
 
size_t size () const
 Size of the string. More...
 
Constructors
 BufferList ()=default
 
 BufferList (Buffer buffer)
 Construct from a Buffer. More...
 
 BufferList (std::string &&str) noexcept
 Construct by taking ownership of a std::string. More...
 

Private Attributes

std::deque< Buffer_buffers {}
 

Detailed Description

A reference-counted discontiguous string that can discard bytes from the front.

Note
Used to model packets that contain multiple sets of headers
  • a payload. This allows us to prepend headers (e.g., to encapsulate a TCP payload in a TCPSegment, and then encapsulate the TCPSegment in an IPv4Datagram) without copying the payload.

Definition at line 57 of file buffer.hh.

Constructor & Destructor Documentation

◆ BufferList() [1/3]

BufferList::BufferList ( )
default

◆ BufferList() [2/3]

BufferList::BufferList ( Buffer  buffer)
inline

Construct from a Buffer.

Definition at line 68 of file buffer.hh.

◆ BufferList() [3/3]

BufferList::BufferList ( std::string &&  str)
inlinenoexcept

Construct by taking ownership of a std::string.

Definition at line 71 of file buffer.hh.

Member Function Documentation

◆ append()

void BufferList::append ( const BufferList other)

Append a BufferList.

Definition at line 15 of file buffer.cc.

◆ buffers()

const std::deque<Buffer>& BufferList::buffers ( ) const
inline

Access the underlying queue of Buffers.

Definition at line 78 of file buffer.hh.

◆ concatenate()

string BufferList::concatenate ( ) const

Make a copy to a new std::string.

Definition at line 34 of file buffer.cc.

◆ operator Buffer()

BufferList::operator Buffer ( ) const

Transform to a Buffer.

Note
Throws an exception unless BufferList is contiguous

Definition at line 21 of file buffer.cc.

◆ remove_prefix()

void BufferList::remove_prefix ( size_t  n)

Discard the first n bytes of the string (does not require a copy or move)

Definition at line 51 of file buffer.cc.

◆ size()

size_t BufferList::size ( ) const

Size of the string.

Definition at line 43 of file buffer.cc.

Member Data Documentation

◆ _buffers

std::deque<Buffer> BufferList::_buffers {}
private

Definition at line 59 of file buffer.hh.


The documentation for this class was generated from the following files: