#include <BinaryTokenizer.h>

Collaboration diagram for Parser::BinaryTokenizer:

Classes

class  InsufficientInput
 

Public Types

typedef uint64_t size_type
 

Public Member Functions

 BinaryTokenizer ()
 
 BinaryTokenizer (const SBuf &data, const bool expectMore=false)
 
void reset (const SBuf &data, const bool expectMore)
 
void reinput (const SBuf &data, const bool expectMore)
 
void commit ()
 make progress: future parsing failures will not rollback beyond this point More...
 
void rollback ()
 resume [incremental] parsing from the last commit point More...
 
bool atEnd () const
 no more bytes to parse or skip More...
 
uint8_t uint8 (const char *description)
 parse a single-byte unsigned integer More...
 
uint16_t uint16 (const char *description)
 parse a two-byte unsigned integer More...
 
uint32_t uint24 (const char *description)
 parse a three-byte unsigned integer (returned as uint32_t) More...
 
uint32_t uint32 (const char *description)
 parse a four-byte unsigned integer More...
 
SBuf area (uint64_t size, const char *description)
 parse size consecutive bytes as an opaque blob More...
 
SBuf pstring8 (const char *description)
 up to 255 byte-long p-string More...
 
SBuf pstring16 (const char *description)
 up to 64 KiB-long p-string More...
 
SBuf pstring24 (const char *description)
 up to 16 MiB-long p-string! More...
 
void skip (uint64_t size, const char *description)
 ignore the next size bytes More...
 
uint64_t parsed () const
 the number of already parsed bytes More...
 
SBuf leftovers () const
 yet unparsed bytes More...
 
void got (uint64_t size, const char *description) const
 debugging helper for parsed multi-field structures More...
 

Public Attributes

const BinaryTokenizerContextcontext
 debugging: thing being parsed More...
 

Protected Member Functions

uint32_t octet ()
 
void want (uint64_t size, const char *description) const
 logs and throws if fewer than size octets remain; no other side effects More...
 
void got (uint32_t value, uint64_t size, const char *description) const
 debugging helper for parsed number fields More...
 
void got (const SBuf &value, uint64_t size, const char *description) const
 debugging helper for parsed areas/blobs More...
 
void skipped (uint64_t size, const char *description) const
 debugging helper for skipped fields More...
 

Private Attributes

SBuf data_
 
uint64_t parsed_
 number of data bytes parsed or skipped More...
 
uint64_t syncPoint_
 where to re-start the next parsing attempt More...
 
bool expectMore_
 whether more data bytes may arrive in the future More...
 

Detailed Description

Safely extracts byte-oriented (i.e., non-textual) fields from raw input. Assume that the integers are stored in network byte order. Supports commit points for atomic incremental parsing of multi-part fields. Throws InsufficientInput when more input is needed to parse the next field. Throws on errors.

Definition at line 44 of file BinaryTokenizer.h.

Member Typedef Documentation

Definition at line 48 of file BinaryTokenizer.h.

Constructor & Destructor Documentation

Parser::BinaryTokenizer::BinaryTokenizer ( )

Definition at line 14 of file BinaryTokenizer.cc.

Parser::BinaryTokenizer::BinaryTokenizer ( const SBuf data,
const bool  expectMore = false 
)
explicit

Definition at line 18 of file BinaryTokenizer.cc.

Member Function Documentation

SBuf Parser::BinaryTokenizer::area ( uint64_t  size,
const char *  description 
)
void Parser::BinaryTokenizer::commit ( )

Definition at line 110 of file BinaryTokenizer.cc.

void Parser::BinaryTokenizer::got ( uint64_t  size,
const char *  description 
) const

Definition at line 54 of file BinaryTokenizer.cc.

References BinaryTokenizer_tail, and debugs.

Referenced by Parser::BinaryTokenizerContext::success().

void Parser::BinaryTokenizer::got ( uint32_t  value,
uint64_t  size,
const char *  description 
) const
protected

Definition at line 62 of file BinaryTokenizer.cc.

References BinaryTokenizer_tail, and debugs.

void Parser::BinaryTokenizer::got ( const SBuf value,
uint64_t  size,
const char *  description 
) const
protected

Definition at line 70 of file BinaryTokenizer.cc.

References BinaryTokenizer_tail, debugs, SBuf::length(), and SBuf::rawContent().

SBuf Parser::BinaryTokenizer::leftovers ( ) const
inline

Definition at line 100 of file BinaryTokenizer.h.

References data_, parsed_, and SBuf::substr().

uint32_t Parser::BinaryTokenizer::octet ( )
protected

Returns the next ready-for-shift byte, adjusting the number of parsed bytes. The larger 32-bit return type helps callers shift/merge octets into numbers. This internal method does not perform out-of-bounds checks.

Definition at line 90 of file BinaryTokenizer.cc.

uint64_t Parser::BinaryTokenizer::parsed ( ) const
inline

Definition at line 97 of file BinaryTokenizer.h.

References parsed_.

Referenced by Parser::BinaryTokenizerContext::success().

SBuf Parser::BinaryTokenizer::pstring24 ( const char *  description)
SBuf Parser::BinaryTokenizer::pstring8 ( const char *  description)
void Parser::BinaryTokenizer::reinput ( const SBuf data,
const bool  expectMore 
)
inline

change input state without changing parsing state this method avoids append overheads during incremental parsing

Definition at line 59 of file BinaryTokenizer.h.

References data, data_, and expectMore_.

void Parser::BinaryTokenizer::reset ( const SBuf data,
const bool  expectMore 
)

restart parsing from the very beginning this method is for using one BinaryTokenizer to parse independent inputs

Definition at line 98 of file BinaryTokenizer.cc.

void Parser::BinaryTokenizer::rollback ( )

Definition at line 104 of file BinaryTokenizer.cc.

void Parser::BinaryTokenizer::skip ( uint64_t  size,
const char *  description 
)
void Parser::BinaryTokenizer::skipped ( uint64_t  size,
const char *  description 
) const
protected

Definition at line 80 of file BinaryTokenizer.cc.

References BinaryTokenizer_tail, and debugs.

uint32_t Parser::BinaryTokenizer::uint24 ( const char *  description)

Definition at line 140 of file BinaryTokenizer.cc.

uint32_t Parser::BinaryTokenizer::uint32 ( const char *  description)

Definition at line 149 of file BinaryTokenizer.cc.

void Parser::BinaryTokenizer::want ( uint64_t  size,
const char *  description 
) const
protected

Definition at line 43 of file BinaryTokenizer.cc.

References BinaryTokenizer_tail, debugs, and Must.

Member Data Documentation

const BinaryTokenizerContext* Parser::BinaryTokenizer::context
SBuf Parser::BinaryTokenizer::data_
private

Definition at line 115 of file BinaryTokenizer.h.

Referenced by leftovers(), and reinput().

bool Parser::BinaryTokenizer::expectMore_
private

Definition at line 118 of file BinaryTokenizer.h.

Referenced by reinput().

uint64_t Parser::BinaryTokenizer::parsed_
private

Definition at line 116 of file BinaryTokenizer.h.

Referenced by leftovers(), and parsed().

uint64_t Parser::BinaryTokenizer::syncPoint_
private

Definition at line 117 of file BinaryTokenizer.h.


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

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors