|
Sponge
CS144's user-space TCP library
|
Go to the documentation of this file.
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;
uint16_t u16()
Parse a 16-bit integer in network byte order from the data stream.
static void u8(std::string &s, const uint8_t val)
Write an 8-bit integer into the data stream in network byte order.
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.
static void u16(std::string &s, const uint16_t val)
Write a 16-bit integer into the data stream in network byte order.
T _parse_int()
Generic integer parsing method (used by u32, u16, u8)
static void _unparse_int(std::string &s, T val)
ParseResult
The result of parsing or unparsing an IP datagram, TCP segment, Ethernet frame, or ARP message.
string as_string(const ParseResult r)
Output a string representation of a ParseResult.
static void u32(std::string &s, const uint32_t val)
Write a 32-bit integer into the data stream in network byte order.
uint8_t u8()
Parse an 8-bit integer in network byte order from the data stream.
@ PacketTooShort
Not enough data to finish parsing.
uint32_t u32()
Parse a 32-bit integer in network byte order from the data stream.