9#ifndef SQUID_SRC_PARSER_BINARYTOKENIZER_H
10#define SQUID_SRC_PARSER_BINARYTOKENIZER_H
57 void reset(
const SBuf &data,
const bool expectMore);
73 uint8_t
uint8(
const char *description);
76 uint16_t
uint16(
const char *description);
79 uint32_t
uint24(
const char *description);
82 uint32_t
uint32(
const char *description);
102 void skip(uint64_t
size,
const char *description);
111 void got(uint64_t
size,
const char *description)
const;
117 void want(uint64_t
size,
const char *description)
const;
118 void got(uint32_t value, uint64_t
size,
const char *description)
const;
119 void got(
const SBuf &value, uint64_t
size,
const char *description)
const;
121 void skipped(uint64_t
size,
const char *description)
const;
124 template <
class InAddr>
enables efficient debugging with concise field names: Hello.version.major
~BinaryTokenizerContext()
uint64_t start
context parsing begins at this tokenizer position
const char *const name
this context description or nullptr
void close()
ends parsing named object; repeated calls OK
BinaryTokenizerContext(BinaryTokenizer &tk, const char *aName)
starts parsing named object
void success()
reports successful parsing of a named object and calls close()
BinaryTokenizer & tokenizer
tokenizer being used for parsing
const BinaryTokenizerContext *const parent
enclosing context or nullptr
uint64_t parsed_
number of data bytes parsed or skipped
SBuf area(uint64_t size, const char *description)
parse size consecutive bytes as an opaque blob
SBuf leftovers() const
yet unparsed bytes
Ip::Address inet4(const char *description)
interpret the next 4 bytes as a raw in_addr structure
void got(uint64_t size, const char *description) const
debugging helper for parsed multi-field structures
SBuf pstring8(const char *description)
up to 255 byte-long p-string
uint64_t syncPoint_
where to re-start the next parsing attempt
void commit()
make progress: future parsing failures will not rollback beyond this point
bool atEnd() const
no more bytes to parse or skip
void reinput(const SBuf &data, const bool expectMore)
void skip(uint64_t size, const char *description)
ignore the next size bytes
void reset(const SBuf &data, const bool expectMore)
bool expectMore_
whether more data bytes may arrive in the future
uint32_t uint32(const char *description)
parse a four-byte unsigned integer
uint32_t uint24(const char *description)
parse a three-byte unsigned integer (returned as uint32_t)
uint64_t parsed() const
the number of already parsed bytes
void want(uint64_t size, const char *description) const
logs and throws if fewer than size octets remain; no other side effects
uint16_t uint16(const char *description)
parse a two-byte unsigned integer
void rollback()
resume [incremental] parsing from the last commit point
Ip::Address inet6(const char *description)
interpret the next 16 bytes as a raw in6_addr structure
uint8_t uint8(const char *description)
parse a single-byte unsigned integer
void skipped(uint64_t size, const char *description) const
debugging helper for skipped fields
Ip::Address inetAny(const char *description)
const BinaryTokenizerContext * context
debugging: thing being parsed
SBuf pstring16(const char *description)
up to 64 KiB-long p-string
SBuf pstring24(const char *description)
up to 16 MiB-long p-string!
::Parser::InsufficientInput InsufficientInput
SBuf substr(size_type pos, size_type n=npos) const
Generic protocol-agnostic parsing tools.