1 #ifndef SPONGE_LIBSPONGE_PARSER_HH
2 #define SPONGE_LIBSPONGE_PARSER_HH
A reference-counted read-only string that can discard bytes from the front.
uint32_t u32()
Parse a 32-bit integer in network byte order from the data stream.
uint16_t u16()
Parse a 16-bit integer in network byte order from the data stream.
ParseResult get_error() const
Get the current value stored in BaseParser::_error.
void set_error(ParseResult res)
Set BaseParser::_error.
ParseResult _error
Result of parsing so far.
T _parse_int()
Generic integer parsing method (used by u32, u16, u8)
void remove_prefix(const size_t n)
Remove n bytes from the buffer.
bool error() const
Returns true if there has been an error.
void _check_size(const size_t size)
Check that there is sufficient data to parse the next token.
uint8_t u8()
Parse an 8-bit integer in network byte order from the data stream.
std::string as_string(const ParseResult r)
Output a string representation of a ParseResult.
ParseResult
The result of parsing or unparsing an IP datagram, TCP segment, Ethernet frame, or ARP message.
@ PacketTooShort
Not enough data to finish parsing.
@ BadChecksum
Bad checksum.
@ TruncatedPacket
Packet length is shorter than header claims.
@ WrongIPVersion
Got a version of IP other than 4.
@ Unsupported
Packet uses unsupported features.
@ HeaderTooShort
Header length is shorter than minimum required.
static void u32(std::string &s, const uint32_t val)
Write a 32-bit integer into the data stream in network byte order.
static void _unparse_int(std::string &s, T val)
static void u16(std::string &s, const uint16_t val)
Write a 16-bit integer into the data stream in network byte order.
static void u8(std::string &s, const uint8_t val)
Write an 8-bit integer into the data stream in network byte order.