8 static constexpr
const char *_names[] = {
17 return _names[
static_cast<size_t>(r)];
21 if (size > _buffer.size()) {
28 constexpr
size_t len =
sizeof(T);
35 for (
size_t i = 0; i < len; i++) {
40 _buffer.remove_prefix(len);
50 _buffer.remove_prefix(n);
55 constexpr
size_t len =
sizeof(T);
56 for (
size_t i = 0; i < len; ++i) {
57 const uint8_t the_byte = (val >> ((len - i - 1) * 8)) & 0xff;
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.
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.
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.
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.
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.