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

#include <parser.hh>

Public Member Functions

 NetParser (Buffer buffer)
 
Buffer buffer () const
 
bool error () const
 Returns true if there has been an error. More...
 
ParseResult get_error () const
 Get the current value stored in BaseParser::_error. More...
 
void remove_prefix (const size_t n)
 Remove n bytes from the buffer. More...
 
void set_error (ParseResult res)
 Set BaseParser::_error. More...
 
uint16_t u16 ()
 Parse a 16-bit integer in network byte order from the data stream. More...
 
uint32_t u32 ()
 Parse a 32-bit integer in network byte order from the data stream. More...
 
uint8_t u8 ()
 Parse an 8-bit integer in network byte order from the data stream. More...
 

Private Member Functions

void _check_size (const size_t size)
 Check that there is sufficient data to parse the next token. More...
 
template<typename T >
_parse_int ()
 Generic integer parsing method (used by u32, u16, u8) More...
 

Private Attributes

Buffer _buffer
 
ParseResult _error = ParseResult::NoError
 Result of parsing so far. More...
 

Detailed Description

Definition at line 25 of file parser.hh.

Constructor & Destructor Documentation

◆ NetParser()

NetParser::NetParser ( Buffer  buffer)
inline

Definition at line 38 of file parser.hh.

Member Function Documentation

◆ _check_size()

void NetParser::_check_size ( const size_t  size)
private

Check that there is sufficient data to parse the next token.

Definition at line 20 of file parser.cc.

◆ _parse_int()

template<typename T >
T NetParser::_parse_int
private

Generic integer parsing method (used by u32, u16, u8)

Definition at line 27 of file parser.cc.

◆ buffer()

Buffer NetParser::buffer ( ) const
inline

Definition at line 40 of file parser.hh.

◆ error()

bool NetParser::error ( ) const
inline

Returns true if there has been an error.

Definition at line 50 of file parser.hh.

◆ get_error()

ParseResult NetParser::get_error ( ) const
inline

Get the current value stored in BaseParser::_error.

Definition at line 43 of file parser.hh.

◆ remove_prefix()

void NetParser::remove_prefix ( const size_t  n)

Remove n bytes from the buffer.

Definition at line 45 of file parser.cc.

◆ set_error()

void NetParser::set_error ( ParseResult  res)
inline

Set BaseParser::_error.

Parameters
[in]resis the value to store in BaseParser::_error

Definition at line 47 of file parser.hh.

◆ u16()

uint16_t NetParser::u16 ( )

Parse a 16-bit integer in network byte order from the data stream.

Definition at line 64 of file parser.cc.

◆ u32()

uint32_t NetParser::u32 ( )

Parse a 32-bit integer in network byte order from the data stream.

Definition at line 62 of file parser.cc.

◆ u8()

uint8_t NetParser::u8 ( )

Parse an 8-bit integer in network byte order from the data stream.

Definition at line 66 of file parser.cc.

Member Data Documentation

◆ _buffer

Buffer NetParser::_buffer
private

Definition at line 27 of file parser.hh.

◆ _error

ParseResult NetParser::_error = ParseResult::NoError
private

Result of parsing so far.

Definition at line 28 of file parser.hh.


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