Mstdlib-1.24.0
Data Parser

Typedefs

typedef struct M_parser M_parser_t
 
typedef M_bool(* M_parser_predicate_func) (unsigned char c)
 

Enumerations

enum  M_PARSER_FLAGS {
  M_PARSER_FLAG_NONE = 0 ,
  M_PARSER_FLAG_TRACKLINES = 1 << 0
}
 
enum  M_PARSER_WHITESPACE_FLAGS {
  M_PARSER_WHITESPACE_NONE = 0 ,
  M_PARSER_WHITESPACE_TO_NEWLINE = 1 << 0 ,
  M_PARSER_WHITESPACE_SPACEONLY = 1 << 1
}
 
enum  M_PARSER_INTEGER_TYPE {
  M_PARSER_INTEGER_ASCII = 0 ,
  M_PARSER_INTEGER_BIGENDIAN = 1 ,
  M_PARSER_INTEGER_LITTLEENDIAN = 2
}
 
enum  M_PARSER_SPLIT_FLAGS {
  M_PARSER_SPLIT_FLAG_NONE = 0 ,
  M_PARSER_SPLIT_FLAG_NODELIM_ERROR = 1 << 0 ,
  M_PARSER_SPLIT_FLAG_DONT_TRIM_LAST = 1 << 1
}
 
enum  M_PARSER_FRAME_BYES {
  M_PARSER_FRAME_NONE = 0 ,
  M_PARSER_FRAME_STX = 1 << 0 ,
  M_PARSER_FRAME_ETX = 1 << 1
}
 
enum  M_PARSER_FRAME_ERROR {
  M_PARSER_FRAME_ERROR_SUCCESS = 0 ,
  M_PARSER_FRAME_ERROR_INVALID ,
  M_PARSER_FRAME_ERROR_NO_STX ,
  M_PARSER_FRAME_ERROR_NO_ETX ,
  M_PARSER_FRAME_ERROR_NO_LRC ,
  M_PARSER_FRAME_ERROR_LRC_CALC_FAILED
}
 

Functions

M_parser_tM_parser_create_const (const unsigned char *buf, size_t len, M_uint32 flags)
 
M_parser_tM_parser_create (M_uint32 flags)
 
void M_parser_destroy (M_parser_t *parser)
 
M_bool M_parser_append (M_parser_t *parser, const unsigned char *data, size_t len)
 
unsigned char * M_parser_direct_write_start (M_parser_t *parser, size_t *len)
 
void M_parser_direct_write_end (M_parser_t *parser, size_t len)
 
size_t M_parser_len (const M_parser_t *parser)
 
size_t M_parser_current_offset (const M_parser_t *parser)
 
size_t M_parser_current_line (const M_parser_t *parser)
 
size_t M_parser_current_column (const M_parser_t *parser)
 
M_bool M_parser_compare (const M_parser_t *parser, const unsigned char *data, size_t data_len)
 
M_bool M_parser_compare_str (const M_parser_t *parser, const char *str, size_t max_len, M_bool casecmp)
 
void M_parser_mark (M_parser_t *parser)
 
void M_parser_mark_clear (M_parser_t *parser)
 
size_t M_parser_mark_len (const M_parser_t *parser)
 
size_t M_parser_mark_rewind (M_parser_t *parser)
 
size_t M_parser_reset (M_parser_t *parser)
 
const unsigned char * M_parser_peek (const M_parser_t *parser)
 
const unsigned char * M_parser_peek_mark (const M_parser_t *parser, size_t *len)
 
M_bool M_parser_peek_byte (const M_parser_t *parser, unsigned char *byte)
 
M_bool M_parser_peek_bytes (const M_parser_t *parser, size_t len, unsigned char *buf)
 
M_bool M_parser_truncate (M_parser_t *parser, size_t len)
 
size_t M_parser_truncate_whitespace (M_parser_t *parser, M_uint32 flags)
 
size_t M_parser_truncate_until (M_parser_t *parser, const unsigned char *pat, size_t len, M_bool eat_pat)
 
size_t M_parser_truncate_charset (M_parser_t *parser, const unsigned char *charset, size_t charset_len)
 
size_t M_parser_truncate_predicate (M_parser_t *parser, M_parser_predicate_func func)
 
size_t M_parser_truncate_predicate_max (M_parser_t *parser, M_parser_predicate_func func, size_t max)
 
size_t M_parser_truncate_chr_predicate (M_parser_t *parser, M_chr_predicate_func func)
 
size_t M_parser_truncate_chr_predicate_max (M_parser_t *parser, M_chr_predicate_func func, size_t max)
 
size_t M_parser_truncate_str_until (M_parser_t *parser, const char *pat, M_bool eat_pat)
 
size_t M_parser_truncate_str_charset (M_parser_t *parser, const char *charset)
 
M_bool M_parser_consume (M_parser_t *parser, size_t len)
 
size_t M_parser_consume_whitespace (M_parser_t *parser, M_uint32 flags)
 
size_t M_parser_consume_until (M_parser_t *parser, const unsigned char *pat, size_t len, M_bool eat_pat)
 
size_t M_parser_consume_boundary (M_parser_t *parser, const unsigned char *pat, size_t len, M_bool eat_pat, M_bool *found)
 
size_t M_parser_consume_charset (M_parser_t *parser, const unsigned char *charset, size_t charset_len)
 
size_t M_parser_consume_predicate (M_parser_t *parser, M_parser_predicate_func func)
 
size_t M_parser_consume_predicate_max (M_parser_t *parser, M_parser_predicate_func func, size_t max)
 
size_t M_parser_consume_chr_predicate (M_parser_t *parser, M_chr_predicate_func func)
 
size_t M_parser_consume_chr_predicate_max (M_parser_t *parser, M_chr_predicate_func func, size_t max)
 
size_t M_parser_consume_str_until (M_parser_t *parser, const char *pat, M_bool eat_pat)
 
size_t M_parser_consume_str_boundary (M_parser_t *parser, const char *pat, M_bool eat_pat, M_bool *found)
 
size_t M_parser_consume_str_charset (M_parser_t *parser, const char *charset)
 
size_t M_parser_consume_not_charset (M_parser_t *parser, const unsigned char *charset, size_t charset_len)
 
size_t M_parser_consume_str_not_charset (M_parser_t *parser, const char *charset)
 
size_t M_parser_consume_eol (M_parser_t *parser)
 
M_bool M_parser_read_int (M_parser_t *parser, enum M_PARSER_INTEGER_TYPE type, size_t len, unsigned char base, M_int64 *integer)
 
M_bool M_parser_read_uint (M_parser_t *parser, enum M_PARSER_INTEGER_TYPE type, size_t len, unsigned char base, M_uint64 *integer)
 
M_bool M_parser_read_uint_bcd (M_parser_t *parser, size_t len, M_uint64 *integer)
 
enum M_DECIMAL_RETVAL M_parser_read_decimal (M_parser_t *parser, size_t len, M_bool truncate_fail, M_decimal_t *decimal)
 
M_bool M_parser_read_byte (M_parser_t *parser, unsigned char *byte)
 
M_bool M_parser_read_bytes (M_parser_t *parser, size_t len, unsigned char *buf)
 
size_t M_parser_read_bytes_max (M_parser_t *parser, size_t len, unsigned char *buf, size_t buf_len)
 
size_t M_parser_read_bytes_until (M_parser_t *parser, unsigned char *buf, size_t buf_len, const unsigned char *pat, size_t pat_len, M_bool eat_pat)
 
size_t M_parser_read_bytes_boundary (M_parser_t *parser, unsigned char *buf, size_t buf_len, const unsigned char *pat, size_t len, M_bool eat_pat, M_bool *found)
 
size_t M_parser_read_bytes_charset (M_parser_t *parser, const unsigned char *charset, size_t charset_len, unsigned char *buf, size_t buf_len)
 
size_t M_parser_read_bytes_not_charset (M_parser_t *parser, const unsigned char *charset, size_t charset_len, unsigned char *buf, size_t buf_len)
 
size_t M_parser_read_bytes_predicate (M_parser_t *parser, M_parser_predicate_func func, unsigned char *buf, size_t buf_len)
 
size_t M_parser_read_bytes_chr_predicate (M_parser_t *parser, M_chr_predicate_func func, unsigned char *buf, size_t buf_len)
 
size_t M_parser_read_bytes_mark (M_parser_t *parser, unsigned char *buf, size_t buf_len)
 
M_bool M_parser_read_str (M_parser_t *parser, size_t len, char *buf, size_t buf_len)
 
size_t M_parser_read_str_max (M_parser_t *parser, size_t len, char *buf, size_t buf_len)
 
size_t M_parser_read_str_until (M_parser_t *parser, char *buf, size_t buf_len, const char *pat, M_bool eat_pat)
 
size_t M_parser_read_str_boundary (M_parser_t *parser, char *buf, size_t buf_len, const char *pat, M_bool eat_pat, M_bool *found)
 
size_t M_parser_read_str_charset (M_parser_t *parser, const char *charset, char *buf, size_t buf_len)
 
size_t M_parser_read_str_not_charset (M_parser_t *parser, const char *charset, char *buf, size_t buf_len)
 
size_t M_parser_read_str_predicate (M_parser_t *parser, M_parser_predicate_func func, char *buf, size_t buf_len)
 
size_t M_parser_read_str_chr_predicate (M_parser_t *parser, M_chr_predicate_func func, char *buf, size_t buf_len)
 
size_t M_parser_read_str_mark (M_parser_t *parser, char *buf, size_t buf_len)
 
char * M_parser_read_strdup (M_parser_t *parser, size_t len)
 
char * M_parser_read_strdup_hex (M_parser_t *parser, size_t len)
 
char * M_parser_read_strdup_until (M_parser_t *parser, const char *pat, M_bool eat_pat)
 
char * M_parser_read_strdup_boundary (M_parser_t *parser, const char *pat, M_bool eat_pat, M_bool *found)
 
char * M_parser_read_strdup_charset (M_parser_t *parser, const char *charset)
 
char * M_parser_read_strdup_not_charset (M_parser_t *parser, const char *charset)
 
char * M_parser_read_strdup_predicate (M_parser_t *parser, M_parser_predicate_func func)
 
char * M_parser_read_strdup_predicate_max (M_parser_t *parser, M_parser_predicate_func func, size_t max)
 
char * M_parser_read_strdup_chr_predicate (M_parser_t *parser, M_chr_predicate_func func)
 
char * M_parser_read_strdup_chr_predicate_max (M_parser_t *parser, M_chr_predicate_func func, size_t max)
 
char * M_parser_read_strdup_mark (M_parser_t *parser)
 
M_bool M_parser_read_buf (M_parser_t *parser, M_buf_t *buf, size_t len)
 
M_bool M_parser_read_buf_hex (M_parser_t *parser, M_buf_t *buf, size_t len)
 
size_t M_parser_read_buf_max (M_parser_t *parser, M_buf_t *buf, size_t len)
 
size_t M_parser_read_buf_until (M_parser_t *parser, M_buf_t *buf, const unsigned char *pat, size_t pat_len, M_bool eat_pat)
 
size_t M_parser_read_buf_boundary (M_parser_t *parser, M_buf_t *buf, const unsigned char *pat, size_t len, M_bool eat_pat, M_bool *found)
 
size_t M_parser_read_buf_charset (M_parser_t *parser, M_buf_t *buf, const unsigned char *charset, size_t charset_len)
 
size_t M_parser_read_buf_not_charset (M_parser_t *parser, M_buf_t *buf, const unsigned char *charset, size_t charset_len)
 
size_t M_parser_read_buf_predicate (M_parser_t *parser, M_buf_t *buf, M_parser_predicate_func func)
 
size_t M_parser_read_buf_predicate_max (M_parser_t *parser, M_buf_t *buf, M_parser_predicate_func func, size_t max)
 
size_t M_parser_read_buf_chr_predicate (M_parser_t *parser, M_buf_t *buf, M_chr_predicate_func func)
 
size_t M_parser_read_buf_chr_predicate_max (M_parser_t *parser, M_buf_t *buf, M_chr_predicate_func func, size_t max)
 
size_t M_parser_read_buf_mark (M_parser_t *parser, M_buf_t *buf)
 
M_parser_tM_parser_read_parser (M_parser_t *parser, size_t len)
 
M_parser_tM_parser_read_parser_until (M_parser_t *parser, const unsigned char *pat, size_t len, M_bool eat_pat)
 
M_parser_tM_parser_read_parser_boundary (M_parser_t *parser, const unsigned char *pat, size_t len, M_bool eat_pat, M_bool *found)
 
M_parser_tM_parser_read_parser_charset (M_parser_t *parser, unsigned const char *charset, size_t charset_len)
 
M_parser_tM_parser_read_parser_predicate (M_parser_t *parser, M_parser_predicate_func func)
 
M_parser_tM_parser_read_parser_predicate_max (M_parser_t *parser, M_parser_predicate_func func, size_t max)
 
M_parser_tM_parser_read_parser_chr_predicate (M_parser_t *parser, M_parser_predicate_func func)
 
M_parser_tM_parser_read_parser_chr_predicate_max (M_parser_t *parser, M_parser_predicate_func func, size_t max)
 
M_parser_tM_parser_read_parser_mark (M_parser_t *parser)
 
M_PARSER_FRAME_ERROR M_parser_read_stxetxlrc_message (M_parser_t *parser, M_parser_t **out, M_uint32 lrc_frame_chars)
 
M_bool M_parser_is_predicate (const M_parser_t *parser, size_t len, M_parser_predicate_func func)
 
M_bool M_parser_is_chr_predicate (const M_parser_t *parser, size_t len, M_chr_predicate_func func)
 
M_bool M_parser_is_charset (const M_parser_t *parser, size_t len, const unsigned char *charset, size_t charset_len)
 
M_bool M_parser_is_str_charset (const M_parser_t *parser, size_t len, const char *charset)
 
M_bool M_parser_is_not_predicate (const M_parser_t *parser, size_t len, M_parser_predicate_func func)
 
M_bool M_parser_is_not_chr_predicate (const M_parser_t *parser, size_t len, M_chr_predicate_func func)
 
M_bool M_parser_is_not_charset (const M_parser_t *parser, size_t len, const unsigned char *charset, size_t charset_len)
 
M_bool M_parser_is_not_str_charset (const M_parser_t *parser, size_t len, const char *charset)
 
M_parser_t ** M_parser_split (M_parser_t *parser, unsigned char delim, size_t maxcnt, M_uint32 flags, size_t *num_output)
 
M_parser_t ** M_parser_split_pat (M_parser_t *parser, const unsigned char *pat, size_t pat_len, size_t maxcnt, M_uint32 flags, size_t *num_output)
 
M_parser_t ** M_parser_split_str_pat (M_parser_t *parser, const char *pat, size_t maxcnt, M_uint32 flags, size_t *num_output)
 
void M_parser_split_free (M_parser_t **parsers, size_t cnt)
 

Detailed Description

Buffer based data parser.

Efficient parser that prevents reading past the end of the data buffer. Has helpers for reading specific types from the buffer (auto conversion). Also supports line and column tracking.

Typedef Documentation

◆ M_parser_t

typedef struct M_parser M_parser_t

◆ M_parser_predicate_func

typedef M_bool(* M_parser_predicate_func) (unsigned char c)

Enumeration Type Documentation

◆ M_PARSER_FLAGS

Flags controlling behavior of the parser.

Enumerator
M_PARSER_FLAG_NONE 

No Flags.

M_PARSER_FLAG_TRACKLINES 

Track lines and columns. This should only be enabled if needed as it will cause an additional data scan.

◆ M_PARSER_WHITESPACE_FLAGS

Flags controlling what constitutes whitespace.

Enumerator
M_PARSER_WHITESPACE_NONE 

Consumes all whitespace

M_PARSER_WHITESPACE_TO_NEWLINE 

Only consume whitespace up to and including the next new line.

M_PARSER_WHITESPACE_SPACEONLY 

Only consume space 0x20 characters.

◆ M_PARSER_INTEGER_TYPE

Integer binary format.

Enumerator
M_PARSER_INTEGER_ASCII 

Integer represented in ASCII form.

M_PARSER_INTEGER_BIGENDIAN 

Integer represented in Big Endian form.

M_PARSER_INTEGER_LITTLEENDIAN 

Integer represented in Little Endian form.

◆ M_PARSER_SPLIT_FLAGS

Splitting flags.

Enumerator
M_PARSER_SPLIT_FLAG_NONE 

No flags, standard behavior

M_PARSER_SPLIT_FLAG_NODELIM_ERROR 

Return an error if the specified delimiter is not found, otherwise all the data is put in a single parser object

M_PARSER_SPLIT_FLAG_DONT_TRIM_LAST 

Don't trim the last section if it is empty. The default is to not return it as a section

◆ M_PARSER_FRAME_BYES

Framing characters.

Enumerator
M_PARSER_FRAME_NONE 

No framing characters.

M_PARSER_FRAME_STX 

STX (0x02)

M_PARSER_FRAME_ETX 

ETX (0x03)

◆ M_PARSER_FRAME_ERROR

STX, ETX, LRC unwrapping responses.

Enumerator
M_PARSER_FRAME_ERROR_SUCCESS 

Success.

M_PARSER_FRAME_ERROR_INVALID 

Invalid input.

M_PARSER_FRAME_ERROR_NO_STX 

Data does not start with STX.

M_PARSER_FRAME_ERROR_NO_ETX 

ETX not found.

M_PARSER_FRAME_ERROR_NO_LRC 

Not enough data for LRC.

M_PARSER_FRAME_ERROR_LRC_CALC_FAILED 

LRC calculation failed.

Function Documentation

◆ M_parser_create_const()

M_parser_t * M_parser_create_const ( const unsigned char *  buf,
size_t  len,
M_uint32  flags 
)

Initialize a parser object using const data.

The object is initialized with constant data which cannot be appended to. Memory is not duplicated and therefore the memory for the buffer pointed to must exist for the life of the parser. The parser will not clean up the memory for the referenced object.

Parameters
[in]bufData to parse, must not be NULL.
[in]lenLength of data to be parsed.
[in]flagsAny of the enum M_PARSER_FLAGS bitwise OR'd together.
Returns
Parser object, or NULL on failure.
See also
M_parser_destroy

◆ M_parser_create()

M_parser_t * M_parser_create ( M_uint32  flags)

Initialize an empty parser object.

Its initial state is empty and data must be appended to it before any data can be parsed.

IMPLEMENTATION NOTE: For efficiency, data which is parsed will be purged from memory when additional internal buffer space is required during an append operation. This is to reclaim space and reduce the number of allocations required when parsing stream-based data.

Returns
Parser object, or NULL on failure.
See also
M_parser_destroy

◆ M_parser_destroy()

void M_parser_destroy ( M_parser_t parser)

Destroy the parser object.

Parameters
[in]parserParser object.

◆ M_parser_append()

M_bool M_parser_append ( M_parser_t parser,
const unsigned char *  data,
size_t  len 
)

Append data to a parser object.

The parser object must have been initialized with M_parser_create(). This will append the data to the internal buffer extending the available length of data to parse.

Parameters
[in,out]parserParser object, but not be a const object.
[in]dataData to append.
[in]lenLength of data to append.
Returns
M_TRUE on success, M_FALSE on misuse.

◆ M_parser_direct_write_start()

unsigned char * M_parser_direct_write_start ( M_parser_t parser,
size_t *  len 
)

Begin a direct write operation. In general, this function should not be used, it is meant as an optimization to prevent double buffering when reading I/O. A writable buffer will be returned of at least the length requested, often it will be much larger. To end the direct write process, M_parser_direct_write_end() must be called with the length actually written. It is not valid to call any other M_parser_*() functions between start and end.

Parameters
[in,out]parserParser object, but not be a const object
[in,out]lenPass in the minimum requested buffer size, outputs the maximum writable buffer size.
Returns
Writable buffer or NULL on failure

◆ M_parser_direct_write_end()

void M_parser_direct_write_end ( M_parser_t parser,
size_t  len 
)

End a direct write operation. Please see M_parser_direct_write_start() for more information. This terminates a direct write sequence regardless of if data was written or not (len = 0 is acceptable).

Parameters
[in,out]parserParser object, but not a const object
[in]lenLength of data written.

◆ M_parser_len()

size_t M_parser_len ( const M_parser_t parser)

Retrieve the length of data remaining in the buffer being parsed.

Parameters
[in]parserParser object.
Returns
Length of remaining data.

◆ M_parser_current_offset()

size_t M_parser_current_offset ( const M_parser_t parser)

Retrieve the total number of bytes processed so far.

Parameters
parserParser object.
Returns
Total number of processed bytes.

◆ M_parser_current_line()

size_t M_parser_current_line ( const M_parser_t parser)

Retrieves the current line number.

Line numbers are determined based on how many \n's have been evaluated in the data stream. This can only be called if M_PARSER_FLAG_TRACKLINES was used during initialization of the parser.

Parameters
[in]parserparser object.
Returns
Line number starting at 1.

◆ M_parser_current_column()

size_t M_parser_current_column ( const M_parser_t parser)

Retrieves the current column for the current line.

The column count resets each time a \n is passed. This can only be called if M_PARSER_FLAG_TRACKLINES was used during initialization of the parser.

Parameters
parserParser object.
Returns
Column number starting at 1.

◆ M_parser_compare()

M_bool M_parser_compare ( const M_parser_t parser,
const unsigned char *  data,
size_t  data_len 
)

Compare parser contents to provided buffer

Does not advance.

Parameters
[in]parserParser object.
[in]dataData to compare.
[in]data_lenLength of data to compare
Returns
M_TRUE if match, M_FALSE otherwise

◆ M_parser_compare_str()

M_bool M_parser_compare_str ( const M_parser_t parser,
const char *  str,
size_t  max_len,
M_bool  casecmp 
)

Compare parser contents to provided string.

Does not advance.

Parameters
[in]parserParser object.
[in]strString data to compare.
[in]max_lenMaximum length of data to compare, 0 for entire string. If 0 is specified, then also the entire parser buffer must be an exact match. If there are extra bytes after the match, this will not be considered an exact match.
[in]casecmpPerform case-insensitive comparison?
Returns
M_TRUE if match, M_FALSE otherwise

◆ M_parser_mark()

void M_parser_mark ( M_parser_t parser)

Marks the current position for future reference in case additional data might need to be pulled from this marked point forward.

If a data position is marked, it will not be eligible to be destroyed/chopped until the marked position is cleared.

Parameters
[in,out]parserParser object.

◆ M_parser_mark_clear()

void M_parser_mark_clear ( M_parser_t parser)

Clears the current marked position, allowing it to be garbage collected.

Parameters
[in,out]parserParser object.

◆ M_parser_mark_len()

size_t M_parser_mark_len ( const M_parser_t parser)

Obtain the length of the marked position to the current position.

Parameters
[in]parserParser object.
Returns
Length or 0 on error.

◆ M_parser_mark_rewind()

size_t M_parser_mark_rewind ( M_parser_t parser)

Rewind data back to the marked position.

This will automaticaly clear the marked position so if the marked position is still needed, the caller must re-mark it.

Parameters
[in,out]parserParser object.
Returns
Number of bytes rewinded or 0 on error.

◆ M_parser_reset()

size_t M_parser_reset ( M_parser_t parser)

Reset set the parser back to the beginning of the data.

This is only applicable to 'const' parsers, and will fail on dynamic parsers. If this scans back past a marked position, the mark will be automatically cleared.

Parameters
[in,out]parserParser object.
Returns
Number of bytes regurgitated or 0 on error.

◆ M_parser_peek()

const unsigned char * M_parser_peek ( const M_parser_t parser)

Retrieve the internal pointer for the current position in the parse buffer.

Parameters
[in]parserParser object.
Returns
Pointer to data.

◆ M_parser_peek_mark()

const unsigned char * M_parser_peek_mark ( const M_parser_t parser,
size_t *  len 
)

Retrieve the internal pointer for the marked position in the parse buffer.

Parameters
[in]parserParser object.
[out]lenLength of marked data.
Returns
Pointer to data.

◆ M_parser_peek_byte()

M_bool M_parser_peek_byte ( const M_parser_t parser,
unsigned char *  byte 
)

Read a single byte from the current buffer without advancing.

Parameters
[in]parserParser object.
[out]byteOutputs byte read.
Returns
M_TRUE on success, M_FALSE on failure.

◆ M_parser_peek_bytes()

M_bool M_parser_peek_bytes ( const M_parser_t parser,
size_t  len,
unsigned char *  buf 
)

Read bytes (binary) from the current buffer and output in the user-provided buffer without advancing.

The data read will not be NULL terminated and the buffer provided must be at least as large as large as the requested data.

Parameters
[in]parserParser object.
[in]lenLength of data to read.
[in,out]bufBuffer to hold output.
Returns
M_TRUE on success, M_FALSE if not enough bytes or other error.

◆ M_parser_truncate()

M_bool M_parser_truncate ( M_parser_t parser,
size_t  len 
)

Truncate the parse buffer at the position specified (relative to the current parse offset).

Parameters
[in,out]parserParser object.
[in]lenLength to truncate to.
Returns
M_TRUE on success, M_FALSE if not enough bytes exist in the data stream or other error.

◆ M_parser_truncate_whitespace()

size_t M_parser_truncate_whitespace ( M_parser_t parser,
M_uint32  flags 
)

Truncate all available whitespace.

Searches backwards from end to start.

Parameters
[in,out]parserParser object.
[in]flagsA bitmap of enum M_PARSER_WHITESPACE_FLAGS.
Returns
Number of bytes consumed.

◆ M_parser_truncate_until()

size_t M_parser_truncate_until ( M_parser_t parser,
const unsigned char *  pat,
size_t  len,
M_bool  eat_pat 
)

Truncate all bytes until the specified sequence of bytes is encountered in the data stream.

Searches backwards from end to start.

Parameters
[in,out]parserParser object.
[in]patSequence of bytes to search for.
[in]lenLength of pattern data.
[in]eat_patShould the sequence of bytes be consumed. Useful for ignoring data until end of comment.
Returns
Number of bytes consumed, or 0 if not found.

◆ M_parser_truncate_charset()

size_t M_parser_truncate_charset ( M_parser_t parser,
const unsigned char *  charset,
size_t  charset_len 
)

Truncate all bytes matching the given charset.

Searches backwards from end to start.

Parameters
[in,out]parserParser object.
[in]charsetCharacter set.
[in]charset_lenLength of given character set.
Returns
Number of bytes consumed, or 0 if none/error.

◆ M_parser_truncate_predicate()

size_t M_parser_truncate_predicate ( M_parser_t parser,
M_parser_predicate_func  func 
)

Truncate all bytes matching the given predicate function.

Searches backwards from end to start.

Parameters
[in,out]parserParser object.
[in]funcPredicate function.
Returns
Number of bytes consumed, or 0 if none/error.

◆ M_parser_truncate_predicate_max()

size_t M_parser_truncate_predicate_max ( M_parser_t parser,
M_parser_predicate_func  func,
size_t  max 
)

Truncate all bytes matching the given predicate function up to a given maximum.

Searches backwards from end to start.

Parameters
[in,out]parserParser object.
[in]funcPredicate function.
[in]maxRequested length of data to read.
Returns
Number of bytes consumed, or 0 if none/error.

◆ M_parser_truncate_chr_predicate()

size_t M_parser_truncate_chr_predicate ( M_parser_t parser,
M_chr_predicate_func  func 
)

Truncate all bytes matching the given chr predicate function.

Searches backwards from end to start.

Parameters
[in,out]parserParser object.
[in]funcPredicate function.
Returns
Number of bytes consumed, or 0 if none/error.

◆ M_parser_truncate_chr_predicate_max()

size_t M_parser_truncate_chr_predicate_max ( M_parser_t parser,
M_chr_predicate_func  func,
size_t  max 
)

Truncate all bytes matching the given chr predicate function up to a given maximum.

Searches backwards from end to start.

Parameters
[in,out]parserParser object.
[in]funcPredicate function.
[in]maxRequested length of data to read.
Returns
Number of bytes consumed, or 0 if none/error.

◆ M_parser_truncate_str_until()

size_t M_parser_truncate_str_until ( M_parser_t parser,
const char *  pat,
M_bool  eat_pat 
)

Truncate all bytes until the specified string is encountered in the data stream.

Searches backwards from end to start.

Parameters
[in,out]parserParser object.
[in]patString to search for.
[in]eat_patShould the sequence of bytes be consumed. Useful for ignoring data until end of comment.
Returns
Number of bytes consumed, or 0 if not found.

◆ M_parser_truncate_str_charset()

size_t M_parser_truncate_str_charset ( M_parser_t parser,
const char *  charset 
)

Truncate all bytes matching the given NULL-terminated charset.

Searches backwards from end to start.

Parameters
[in,out]parserParser object.
[in]charsetCharacter set, NULL-terminated.
Returns
Number of bytes consumed, or 0 if none/error.

◆ M_parser_consume()

M_bool M_parser_consume ( M_parser_t parser,
size_t  len 
)

Consume the given number of bytes.

Parameters
[in,out]parserParser object.
[in]lenNumber of bytes to consume.
Returns
M_TRUE on success, M_FALSE if not enough bytes.

◆ M_parser_consume_whitespace()

size_t M_parser_consume_whitespace ( M_parser_t parser,
M_uint32  flags 
)

Consume all available whitespace.

Parameters
[in,out]parserParser object.
[in]flagsA bitmap of enum M_PARSER_WHITESPACE_FLAGS.
Returns
Number of bytes consumed.

◆ M_parser_consume_until()

size_t M_parser_consume_until ( M_parser_t parser,
const unsigned char *  pat,
size_t  len,
M_bool  eat_pat 
)

Consume all bytes until the specified sequence of bytes is encountered in the data stream.

Parameters
[in,out]parserParser object.
[in]patSequence of bytes to search for.
[in]lenLength of pattern data.
[in]eat_patShould the sequence of bytes be consumed. Useful for ignoring data until end of comment.
Returns
Number of bytes consumed, or 0 if not found.

◆ M_parser_consume_boundary()

size_t M_parser_consume_boundary ( M_parser_t parser,
const unsigned char *  pat,
size_t  len,
M_bool  eat_pat,
M_bool *  found 
)

Consume all bytes before a pat.

Will stop if parser ends with a partially matching pat. Will only eat the pattern if a full pat is found.

Will stop consuming if a partial match of the pat is found. E.g. parser = "ABC1234" pat = "12345". Will consume "ABC" leaving "12345". If more data is added and and parser = "123461234". Will consume "12346". If more data is added and and parser = "1234612345" Will consume everything is eat_path is M_TRUE. Otherwise, "12346".

Parameters
[in,out]parserParser object.
[in]patSequence of bytes to search for.
[in]lenLength of pattern data.
[in]eat_patShould the sequence of bytes be consumed. Useful for ignoring data until end of comment.
[out]foundWas the full pat found. A partial boundy might still be in the parser if M_FALSE.
Returns
Number of bytes consumed. 0 if not found or if starts with a partial pat match.

◆ M_parser_consume_charset()

size_t M_parser_consume_charset ( M_parser_t parser,
const unsigned char *  charset,
size_t  charset_len 
)

Consume all bytes matching the given charset.

Parameters
[in,out]parserParser object.
[in]charsetCharacter set.
[in]charset_lenLength of given character set.
Returns
Number of bytes consumed, or 0 if none/error.

◆ M_parser_consume_predicate()

size_t M_parser_consume_predicate ( M_parser_t parser,
M_parser_predicate_func  func 
)

Consume all bytes matching the given predicate function.

Parameters
[in,out]parserParser object.
[in]funcPredicate function.
Returns
Number of bytes consumed, or 0 if none/error.

◆ M_parser_consume_predicate_max()

size_t M_parser_consume_predicate_max ( M_parser_t parser,
M_parser_predicate_func  func,
size_t  max 
)

Consume all bytes matching the given predicate function up to a given maximum.

Parameters
[in,out]parserParser object.
[in]funcPredicate function.
[in]maxRequested length of data to read.
Returns
Number of bytes consumed, or 0 if none/error.

◆ M_parser_consume_chr_predicate()

size_t M_parser_consume_chr_predicate ( M_parser_t parser,
M_chr_predicate_func  func 
)

Consume all bytes matching the given chr predicate function.

Parameters
[in,out]parserParser object.
[in]funcPredicate function.
Returns
Number of bytes consumed, or 0 if none/error.

◆ M_parser_consume_chr_predicate_max()

size_t M_parser_consume_chr_predicate_max ( M_parser_t parser,
M_chr_predicate_func  func,
size_t  max 
)

Consume all bytes matching the given chr predicate function up to a given maximum.

Parameters
[in,out]parserParser object.
[in]funcPredicate function.
[in]maxRequested length of data to read.
Returns
Number of bytes consumed, or 0 if none/error.

◆ M_parser_consume_str_until()

size_t M_parser_consume_str_until ( M_parser_t parser,
const char *  pat,
M_bool  eat_pat 
)

Consume all bytes until the specified string is encountered in the data stream.

Parameters
[in,out]parserParser object.
[in]patString to search for.
[in]eat_patShould the sequence of bytes be consumed. Useful for ignoring data until end of comment.
Returns
Number of bytes consumed, or 0 if not found.

◆ M_parser_consume_str_boundary()

size_t M_parser_consume_str_boundary ( M_parser_t parser,
const char *  pat,
M_bool  eat_pat,
M_bool *  found 
)

Consume all bytes before a pat.

Will stop if parser ends with a partially matching pat. Will only eat the pattern if a full pat is found.

Will stop consuming if a partial match of the pat is found. E.g. parser = "ABC1234" pat = "12345". Will consume "ABC" leaving "12345". If more data is added and and parser = "123461234". Will consume "12346". If more data is added and and parser = "1234612345" Will consume everything is eat_path is M_TRUE. Otherwise, "12346".

Parameters
[in,out]parserParser object.
[in]patString to search for.
[in]eat_patShould the sequence of bytes be consumed. Useful for ignoring data until end of comment.
[out]foundWas the full pat found. A partial boundy might still be in the parser if M_FALSE.
Returns
Number of bytes consumed. 0 if not found or if starts with a partial pat match.

◆ M_parser_consume_str_charset()

size_t M_parser_consume_str_charset ( M_parser_t parser,
const char *  charset 
)

Consume all bytes matching the given NULL-terminated charset.

Parameters
[in,out]parserParser object.
[in]charsetCharacter set, NULL-terminated.
Returns
Number of bytes consumed, or 0 if none/error.

◆ M_parser_consume_not_charset()

size_t M_parser_consume_not_charset ( M_parser_t parser,
const unsigned char *  charset,
size_t  charset_len 
)

Consume all bytes not matching the given charset.

Parameters
[in,out]parserParser object.
[in]charsetCharacter set, NULL-terminated.
[in]charset_lenLength of given character set.
Returns
Number of bytes consumed, or 0 if none/error.

◆ M_parser_consume_str_not_charset()

size_t M_parser_consume_str_not_charset ( M_parser_t parser,
const char *  charset 
)

Consume all bytes not matching the given NULL-terminated charset.

Parameters
[in,out]parserParser object.
[in]charsetCharacter set, NULL-terminated.
Returns
Number of bytes consumed, or 0 if none/error.

◆ M_parser_consume_eol()

size_t M_parser_consume_eol ( M_parser_t parser)

Consume all bytes until and including the next end of line.

Useful for ignoring data until end of single-line comment. If there is no new line, will consume all remaining data.

Parameters
[in,out]parserParser object.
Returns
Number of bytes consumed.

◆ M_parser_read_int()

M_bool M_parser_read_int ( M_parser_t parser,
enum M_PARSER_INTEGER_TYPE  type,
size_t  len,
unsigned char  base,
M_int64 *  integer 
)

Read a signed integer from the current buffer and advance.

For ASCII formatted integers:

  • if len is not specified, it will read up until the first non-numeric character is encountered. At least one numeric must be encountered or it is considered an error.
  • if len is specified, the integer must be exactly that length (no shorter) or it is considered an error.
  • if base is specified as 0, will attempt to auto-detect the base.

For BigEndian or Little Endian formatted integers:

  • The len is mandatory, and base is ignored. Maximum len is 8.
Parameters
[in,out]parserParser object.
[in]typeHow integer is represented in the data stream.
[in]lenLength of integer, or 0 to auto-determine for ASCII.
[in]baseBase represented in ASCII, or 0 to auto-determine (or non-ascii).
[out]integerInteger storage.
Returns
M_FALSE on failure, M_TRUE on success.

◆ M_parser_read_uint()

M_bool M_parser_read_uint ( M_parser_t parser,
enum M_PARSER_INTEGER_TYPE  type,
size_t  len,
unsigned char  base,
M_uint64 *  integer 
)

Read an unsigned integer from the current buffer and advance.

See M_parser_read_int() for details on usage as requirements are the same.

Parameters
[in,out]parserParser object.
[in]typeHow integer is represented in the data stream.
[in]lenLength of integer, or 0 to auto-determine for ASCII.
[in]baseBase represented in ASCII, or 0 to auto-determine (or non-ascii).
[out]integerInteger storage.
Returns
M_FALSE on failure, M_TRUE on success.
See also
M_parser_read_int

◆ M_parser_read_uint_bcd()

M_bool M_parser_read_uint_bcd ( M_parser_t parser,
size_t  len,
M_uint64 *  integer 
)

Read and unsigned Binary Coded Decimal integer from the current buffer and advance

Parameters
[in,out]parserParser object.
[in]lenLength of integer in bytes.
[out]integerInteger storage.
Returns
M_FALSE on failure, M_TRUE on success.

◆ M_parser_read_decimal()

enum M_DECIMAL_RETVAL M_parser_read_decimal ( M_parser_t parser,
size_t  len,
M_bool  truncate_fail,
M_decimal_t decimal 
)

Read a decimal number from current buffer and advance.

The number must be represented in base 10 and in ASCII form.

Parameters
[in,out]parserParser object.
[in]lenLength of decimal, or 0 to auto-determine.
[in]truncate_failM_TRUE to treat a truncation as a failure and not increment the consumer. M_FALSE otherwise.
[out]decimalDecimal storage.
Returns
enum M_DECIMAL_RETVAL values.

◆ M_parser_read_byte()

M_bool M_parser_read_byte ( M_parser_t parser,
unsigned char *  byte 
)

Read a single byte from the current buffer and advance.

Parameters
[in,out]parserParser object.
[out]byteOutputs byte read.
Returns
M_TRUE on success, M_FALSE on failure.

◆ M_parser_read_bytes()

M_bool M_parser_read_bytes ( M_parser_t parser,
size_t  len,
unsigned char *  buf 
)

Read the exact number of bytes (binary) from the current buffer and output in the user-provided buffer and advance. If there are fewer than the requested bytes available, an error will be returned.

The data read will not be NULL terminated and the buffer provided must be at least as large as as the requested data.

Parameters
[in,out]parserParser object.
[in]lenLength of data to read.
[out]bufBuffer to hold output.
Returns
M_TRUE on success, M_FALSE if not enough bytes or other error.

◆ M_parser_read_bytes_max()

size_t M_parser_read_bytes_max ( M_parser_t parser,
size_t  len,
unsigned char *  buf,
size_t  buf_len 
)

Read bytes (binary) from the current buffer and output in the user-provided buffer and advance.

The data read will not be NULL terminated and the buffer provided must be at least as large as large as the requested data. If the length of data specified is not available, it will return the number of bytes actually read.

Parameters
[in,out]parserParser object.
[in]lenRequested length of data to read.
[out]bufBuffer to hold output.
[in]buf_lenLength of buffer to hold output.
Returns
number of bytes read, or 0 on error or no bytes available.

◆ M_parser_read_bytes_until()

size_t M_parser_read_bytes_until ( M_parser_t parser,
unsigned char *  buf,
size_t  buf_len,
const unsigned char *  pat,
size_t  pat_len,
M_bool  eat_pat 
)

Read bytes (binary) until the specified sequence of bytes is encountered in the data stream.

Parameters
[in,out]parserParser object.
[out]bufBuffer to hold output.
[in]buf_lenLength of buffer to hold output.
[in]patSequence of bytes to search for.
[in]pat_lenLength of pattern data.
[in]eat_patShould the sequence of bytes be consumed. Useful for ignoring data until end of comment.
Returns
number of bytes read, or 0 on error or no bytes available.

◆ M_parser_read_bytes_boundary()

size_t M_parser_read_bytes_boundary ( M_parser_t parser,
unsigned char *  buf,
size_t  buf_len,
const unsigned char *  pat,
size_t  len,
M_bool  eat_pat,
M_bool *  found 
)

Read bytes (binary) until the specified pat is encountered in the data stream.

The data read will not be NULL terminated.

Will stop if parser ends with a partially matching pat. Will only eat the pattern if a full pat is found.

Parameters
[in,out]parserParser object.
[out]bufBuffer to hold output.
[in]buf_lenLength of buffer to hold output.
[in]patSequence of bytes to search for.
[in]lenLength of pattern data.
[in]eat_patShould the sequence of bytes be consumed. Useful for ignoring data until end of comment.
[out]foundWas the full pat found. A partial boundy might still be in the parser if M_FALSE.
Returns
number of bytes read, or 0 on error or no bytes available.

◆ M_parser_read_bytes_charset()

size_t M_parser_read_bytes_charset ( M_parser_t parser,
const unsigned char *  charset,
size_t  charset_len,
unsigned char *  buf,
size_t  buf_len 
)

Read bytes (binary) from the current buffer as long as the bytes match the provided character set, output in the user-provided buffer and advance.

The data read will not be NULL terminated.

Parameters
[in,out]parserParser object.
[in]charsetArray of characters that are allowed.
[in]charset_lenLength of character set.
[out]bufBuffer to store result.
[in]buf_lenSize of result buffer.
Returns
Length of data read, or 0 on error.

◆ M_parser_read_bytes_not_charset()

size_t M_parser_read_bytes_not_charset ( M_parser_t parser,
const unsigned char *  charset,
size_t  charset_len,
unsigned char *  buf,
size_t  buf_len 
)

Read bytes (binary) from the current buffer as long as the bytes do not match the provided character set, output in the user-provided buffer and advance.

The data read will not be NULL terminated.

Parameters
[in,out]parserParser object.
[in]charsetArray of characters that are allowed.
[in]charset_lenLength of character set.
[out]bufBuffer to store result.
[in]buf_lenSize of result buffer.
Returns
Length of data read, or 0 on error.

◆ M_parser_read_bytes_predicate()

size_t M_parser_read_bytes_predicate ( M_parser_t parser,
M_parser_predicate_func  func,
unsigned char *  buf,
size_t  buf_len 
)

Read bytes (binary) from the current buffer as long as the bytes match the provided predicate, output in the user-provided buffer and advance.

The data read will not be NULL terminated.

Parameters
[in,out]parserParser object.
[in]funcPredicate function.
[out]bufBuffer to store result.
[in]buf_lenSize of result buffer.
Returns
Length of data read, or 0 on error.

◆ M_parser_read_bytes_chr_predicate()

size_t M_parser_read_bytes_chr_predicate ( M_parser_t parser,
M_chr_predicate_func  func,
unsigned char *  buf,
size_t  buf_len 
)

Read bytes (binary) from the current buffer as long as the bytes match the provided chr predicate, output in the user-provided buffer and advance.

The data read will not be NULL terminated.

Parameters
[in,out]parserParser object.
[in]funcPredicate function.
[out]bufBuffer to store result.
[in]buf_lenSize of result buffer.
Returns
Length of data read, or 0 on error.

◆ M_parser_read_bytes_mark()

size_t M_parser_read_bytes_mark ( M_parser_t parser,
unsigned char *  buf,
size_t  buf_len 
)

Read data from a marked position until the current parser position.

The marked position will be automatically cleared. Provided buffer must be at least M_parser_mark_len() bytes long.

Parameters
[in,out]parserParser object.
[out]bufBuffer to store result.
[in]buf_lenSize of result buffer.
Returns
number of bytes written to buffer or 0 on error.

◆ M_parser_read_str()

M_bool M_parser_read_str ( M_parser_t parser,
size_t  len,
char *  buf,
size_t  buf_len 
)

Read a string from the current buffer of the exact given length, output in the user-provided buffer and advance. If there are insufficient bytes a failure will be returned.

The length of the requested string must be at least one byte shorter than the buffer size to account for the null termination. If you do not already have a buffer, use M_parser_read_strdup() which will return a newly allocated buffer for you.

Parameters
[in,out]parserParser object.
[in]lenLength of string to read (must be at least one byte shorter than buf_len).
[out]bufOutput pointer to store result.
[in]buf_lenLength of output buffer (must be at least one byte greater than len).
Returns
M_TRUE on success, or M_FALSE if not enough bytes or other error.
See also
M_parser_read_strdup

◆ M_parser_read_str_max()

size_t M_parser_read_str_max ( M_parser_t parser,
size_t  len,
char *  buf,
size_t  buf_len 
)

Read a string from the current buffer, output in the user-provided buffer and advance.

The length of the requested string must be at least one byte shorter than the buffer size to account for the null termination. If you do not already have a buffer, use M_parser_read_strdup() which will return a newly allocated buffer for you.

Parameters
[in,out]parserParser object.
[in]lenRequested length of string to read (must be at least one byte shorter than buf_len).
[out]bufOutput pointer to store result.
[in]buf_lenLength of output buffer (must be at least one byte greater than len).
Returns
number of bytes read, or 0 on failure.
See also
M_parser_read_str

◆ M_parser_read_str_until()

size_t M_parser_read_str_until ( M_parser_t parser,
char *  buf,
size_t  buf_len,
const char *  pat,
M_bool  eat_pat 
)

Read data until the specified sequence of bytes is encountered in the data stream.

Parameters
[in,out]parserParser object.
[out]bufBuffer to hold output.
[in]buf_lenLength of buffer to hold output.
[in]patString to search for.
[in]eat_patShould the sequence of bytes be consumed. Useful for ignoring data until end of comment.
Returns
number of bytes read, or 0 on error or no bytes available.

◆ M_parser_read_str_boundary()

size_t M_parser_read_str_boundary ( M_parser_t parser,
char *  buf,
size_t  buf_len,
const char *  pat,
M_bool  eat_pat,
M_bool *  found 
)

Read data until the specified pat is encountered in the data stream.

Will stop if parser ends with a partially matching pat. Will only eat the pattern if a full pat is found.

Parameters
[in,out]parserParser object.
[out]bufBuffer to hold output.
[in]buf_lenLength of buffer to hold output.
[in]patString to search for.
[in]eat_patShould the sequence of bytes be consumed. Useful for ignoring data until end of comment.
[out]foundWas the full pat found. A partial boundy might still be in the parser if M_FALSE.
Returns
number of bytes read, or 0 on error or no bytes available.

◆ M_parser_read_str_charset()

size_t M_parser_read_str_charset ( M_parser_t parser,
const char *  charset,
char *  buf,
size_t  buf_len 
)

Read data from the buffer for as long as it matches one of the bytes in the given character set and advance.

Put the resulting bytes in the provided buffer.

Parameters
[in,out]parserParser object.
[in]charsetArray of characters that are allowed, NULL terminated.
[out]bufBuffer to store result. Will be NULL terminated.
[in]buf_lenSize of result buffer.
Returns
Length of data read, or 0 on error.
See also
M_parser_read_strdup_charset

◆ M_parser_read_str_not_charset()

size_t M_parser_read_str_not_charset ( M_parser_t parser,
const char *  charset,
char *  buf,
size_t  buf_len 
)

Read data from the buffer for as long as it does not match one of the bytes in the given character set and advance.

Put the resulting bytes in the provided buffer.

Parameters
[in,out]parserParser object.
[in]charsetArray of characters that are allowed, NULL terminated.
[out]bufBuffer to store result. Will be NULL terminated.
[in]buf_lenSize of result buffer.
Returns
Length of data read, or 0 on error.
See also
M_parser_read_strdup_charset

◆ M_parser_read_str_predicate()

size_t M_parser_read_str_predicate ( M_parser_t parser,
M_parser_predicate_func  func,
char *  buf,
size_t  buf_len 
)

Read data from the buffer for as long as it matches the given predicate function and advance.

Put the resulting bytes in the provided buffer.

Parameters
[in,out]parserParser object.
[in]funcpredicate function.
[out]bufBuffer to store result. Will be NULL terminated.
[in]buf_lenSize of result buffer.
Returns
Length of data read, or 0 on error.
See also
M_parser_read_strdup_predicate

◆ M_parser_read_str_chr_predicate()

size_t M_parser_read_str_chr_predicate ( M_parser_t parser,
M_chr_predicate_func  func,
char *  buf,
size_t  buf_len 
)

Read data from the buffer for as long as it matches the given chr predicate function and advance.

Put the resulting bytes in the provided buffer.

Parameters
[in,out]parserParser object.
[in]funcpredicate function.
[out]bufBuffer to store result. Will be NULL terminated.
[in]buf_lenSize of result buffer.
Returns
Length of data read, or 0 on error.
See also
M_parser_read_strdup_predicate

◆ M_parser_read_str_mark()

size_t M_parser_read_str_mark ( M_parser_t parser,
char *  buf,
size_t  buf_len 
)

Read data from a marked position until the current parser position.

The marked position will be automatically cleared. Provided buffer must be at least M_parser_mark_len() bytes plus the NULL terminator.

Parameters
[in,out]parserParser object.
[out]bufBuffer to store result.
[in]buf_lenSize of result buffer.
Returns
Number of bytes written to buffer or 0 on error.

◆ M_parser_read_strdup()

char * M_parser_read_strdup ( M_parser_t parser,
size_t  len 
)

Read a string for the given length from the current buffer, allocates an output buffer and advance.

Parameters
[in,out]parserParser object.
[in]lenLength of string to read.
Returns
Buffer containing the string on success, or NULL on failure.
See also
M_parser_read_str

◆ M_parser_read_strdup_hex()

char * M_parser_read_strdup_hex ( M_parser_t parser,
size_t  len 
)

Read bytes (binary) from the parser, return as hex-encoded string and advance.

Parameters
[in,out]parserParser object to read binary bytes from.
[in]lenNumber of binary bytes to read from parser.
Returns
null-terminated hex string on success, NULL if not enough bytes or other error
See also
M_parser_read_buf_hex

◆ M_parser_read_strdup_until()

char * M_parser_read_strdup_until ( M_parser_t parser,
const char *  pat,
M_bool  eat_pat 
)

Read data until the specified sequence of bytes is encountered in the data stream.

Put the resulting bytes in a newly allocated buffer.

Parameters
[in,out]parserParser object.
[in]patSequence of bytes to search for.
[in]eat_patShould the sequence of bytes be consumed. Useful for ignoring data until end of comment.
Returns
number of bytes read, or 0 on error or no bytes available.

◆ M_parser_read_strdup_boundary()

char * M_parser_read_strdup_boundary ( M_parser_t parser,
const char *  pat,
M_bool  eat_pat,
M_bool *  found 
)

Read data until the specified pat is encountered in the data stream.

Will stop if parser ends with a partially matching pat. Will only eat the pattern if a full pat is found.

Put the resulting bytes in a newly allocated buffer.

Parameters
[in,out]parserParser object.
[in]patString to search for.
[in]eat_patShould the sequence of bytes be consumed. Useful for ignoring data until end of comment.
[out]foundWas the full pat found. A partial boundy might still be in the parser if M_FALSE.
Returns
number of bytes read, or 0 on error or no bytes available.

◆ M_parser_read_strdup_charset()

char * M_parser_read_strdup_charset ( M_parser_t parser,
const char *  charset 
)

Read data from the buffer for as long as it matches one of the bytes in the given character set and advance.

Put the resulting bytes in a newly allocated buffer.

Parameters
[in,out]parserParser object.
[in]charsetArray of characters that are allowed, NULL terminated.
Returns
NULL-terminated result buffer, or NULL on error.
See also
M_parser_read_str_charset

◆ M_parser_read_strdup_not_charset()

char * M_parser_read_strdup_not_charset ( M_parser_t parser,
const char *  charset 
)

Read data from the buffer for as long as it does not match one of the bytes in the given character set and advance.

Put the resulting bytes in a newly allocated buffer.

Parameters
[in,out]parserParser object.
[in]charsetArray of characters that are allowed, NULL terminated.
Returns
NULL-terminated result buffer, or NULL on error.
See also
M_parser_read_str_not_charset

◆ M_parser_read_strdup_predicate()

char * M_parser_read_strdup_predicate ( M_parser_t parser,
M_parser_predicate_func  func 
)

Read data from the buffer for as long as it matches the given predicate function and advance.

Put the resulting bytes in a newly allocated buffer.

Parameters
[in,out]parserParser object.
[in]funcPredicate function.
Returns
NULL-terminated result buffer, or NULL on error.
See also
M_parser_read_str_predicate

◆ M_parser_read_strdup_predicate_max()

char * M_parser_read_strdup_predicate_max ( M_parser_t parser,
M_parser_predicate_func  func,
size_t  max 
)

Read data from the buffer for as long as it matches the given predicate function up to a given maximum and advance.

Put the resulting bytes in a newly allocated buffer.

Parameters
[in,out]parserParser object.
[in]funcPredicate function.
[in]maxRequested length of data to read.
Returns
NULL-terminated result buffer, or NULL on error.
See also
M_parser_read_str_predicate

◆ M_parser_read_strdup_chr_predicate()

char * M_parser_read_strdup_chr_predicate ( M_parser_t parser,
M_chr_predicate_func  func 
)

Read data from the buffer for as long as it matches the given predicate function and advance.

Put the resulting bytes in a newly allocated buffer.

Parameters
[in,out]parserParser object.
[in]funcpredicate function.
Returns
NULL-terminated result buffer, or NULL on error.
See also
M_parser_read_str_predicate

◆ M_parser_read_strdup_chr_predicate_max()

char * M_parser_read_strdup_chr_predicate_max ( M_parser_t parser,
M_chr_predicate_func  func,
size_t  max 
)

Read data from the buffer for as long as it matches the given predicate function up to a given maximum and advance.

Put the resulting bytes in a newly allocated buffer.

Parameters
[in,out]parserParser object.
[in]funcpredicate function.
[in]maxRequested length of data to read.
Returns
NULL-terminated result buffer, or NULL on error.
See also
M_parser_read_str_predicate

◆ M_parser_read_strdup_mark()

char * M_parser_read_strdup_mark ( M_parser_t parser)

Read data from a marked position until the current parser position.

The marked position will be automatically cleared. An allocated buffer with the requested data will be returned, NULL terminated.

Parameters
[in,out]parserParser object.
Returns
NULL-terminated result, or NULL on error.

◆ M_parser_read_buf()

M_bool M_parser_read_buf ( M_parser_t parser,
M_buf_t buf,
size_t  len 
)

Read the exact number of bytes (binary) from the current buffer and output in the user-provided buffer and advance.

If there are fewer than the requested bytes available, an error will be returned.

The data read will not be NULL terminated.

Parameters
[in,out]parserParser object.
[out]bufBuffer to hold output.
[in]lenLength of data to read.
Returns
M_TRUE on success, M_FALSE if not enough bytes or other error.

◆ M_parser_read_buf_hex()

M_bool M_parser_read_buf_hex ( M_parser_t parser,
M_buf_t buf,
size_t  len 
)

Read bytes (binary) from the parser, write as hex-encoded string into the provided buffer, and advance.

Parameters
[in,out]parserParser object to read binary bytes from.
[out]bufBuffer to hold hex-ascii output.
[in]lenNumber of binary bytes to read from parser.
Returns
M_TRUE on success, M_FALSE if not enough bytes or other error.

◆ M_parser_read_buf_max()

size_t M_parser_read_buf_max ( M_parser_t parser,
M_buf_t buf,
size_t  len 
)

Read bytes (binary) from the current buffer and output in the user-provided buffer and advance.

The data read will not be NULL terminated. If the length of data specified is not available, it will return the number of bytes actually read.

Parameters
[in,out]parserParser object.
[out]bufBuffer to hold output.
[in]lenRequested length of data to read.
Returns
number of bytes read, or 0 on error or no bytes available.

◆ M_parser_read_buf_until()

size_t M_parser_read_buf_until ( M_parser_t parser,
M_buf_t buf,
const unsigned char *  pat,
size_t  pat_len,
M_bool  eat_pat 
)

Read bytes (binary) until the specified sequence of bytes is encountered in the data stream.

The data read will not be NULL terminated.

Parameters
[in,out]parserParser object.
[out]bufBuffer to hold output.
[in]patSequence of bytes to search for.
[in]pat_lenLength of pattern data.
[in]eat_patShould the sequence of bytes be consumed. Useful for ignoring data until end of comment.
Returns
number of bytes read, or 0 on error or no bytes available.

◆ M_parser_read_buf_boundary()

size_t M_parser_read_buf_boundary ( M_parser_t parser,
M_buf_t buf,
const unsigned char *  pat,
size_t  len,
M_bool  eat_pat,
M_bool *  found 
)

Read bytes (binary) until the specified pat is encountered in the data stream.

The data read will not be NULL terminated.

Will stop if parser ends with a partially matching pat. Will only eat the pattern if a full pat is found.

Parameters
[in,out]parserParser object.
[out]bufBuffer to hold output.
[in]patSequence of bytes to search for.
[in]lenLength of pattern data.
[in]eat_patShould the sequence of bytes be consumed. Useful for ignoring data until end of comment.
[out]foundWas the full pat found. A partial boundy might still be in the parser if M_FALSE.
Returns
number of bytes read, or 0 on error or no bytes available.

◆ M_parser_read_buf_charset()

size_t M_parser_read_buf_charset ( M_parser_t parser,
M_buf_t buf,
const unsigned char *  charset,
size_t  charset_len 
)

Read bytes (binary) from the current buffer as long as the bytes match the provided character set, output in the user-provided buffer and advance.

The data read will not be NULL terminated.

Parameters
[in,out]parserParser object.
[out]bufBuffer to store result.
[in]charsetArray of characters that are allowed.
[in]charset_lenLength of character set.
Returns
Length of data read, or 0 on error.

◆ M_parser_read_buf_not_charset()

size_t M_parser_read_buf_not_charset ( M_parser_t parser,
M_buf_t buf,
const unsigned char *  charset,
size_t  charset_len 
)

Read bytes (binary) from the current buffer as long as the bytes do not match the provided character set, output in the user-provided buffer and advance.

The data read will not be NULL terminated.

Parameters
[in,out]parserParser object.
[out]bufBuffer to store result.
[in]charsetArray of characters that are allowed.
[in]charset_lenLength of character set.
Returns
Length of data read, or 0 on error.

◆ M_parser_read_buf_predicate()

size_t M_parser_read_buf_predicate ( M_parser_t parser,
M_buf_t buf,
M_parser_predicate_func  func 
)

Read bytes (binary) from the current buffer as long as the bytes match the provided predicate, output in the user-provided buffer and advance.

The data read will not be NULL terminated.

Parameters
[in,out]parserParser object.
[out]bufBuffer to store result.
[in]funcPredicate function.
Returns
Length of data read, or 0 on error.

◆ M_parser_read_buf_predicate_max()

size_t M_parser_read_buf_predicate_max ( M_parser_t parser,
M_buf_t buf,
M_parser_predicate_func  func,
size_t  max 
)

Read bytes (binary) from the current buffer as long as the bytes match the provided predicate up to a given maximum, output in the user-provided buffer and advance.

The data read will not be NULL terminated.

Parameters
[in,out]parserParser object.
[out]bufBuffer to store result.
[in]funcPredicate function.
[in]maxRequested length of data to read.
Returns
Length of data read, or 0 on error.

◆ M_parser_read_buf_chr_predicate()

size_t M_parser_read_buf_chr_predicate ( M_parser_t parser,
M_buf_t buf,
M_chr_predicate_func  func 
)

Read bytes (binary) from the current buffer as long as the bytes match the provided chr predicate, output in the user-provided buffer and advance.

The data read will not be NULL terminated.

Parameters
[in,out]parserParser object.
[out]bufBuffer to store result.
[in]funcPredicate function.
Returns
Length of data read, or 0 on error.

◆ M_parser_read_buf_chr_predicate_max()

size_t M_parser_read_buf_chr_predicate_max ( M_parser_t parser,
M_buf_t buf,
M_chr_predicate_func  func,
size_t  max 
)

Read bytes (binary) from the current buffer as long as the bytes match the provided chr predicate up to a given maximum, output in the user-provided buffer and advance.

The data read will not be NULL terminated.

Parameters
[in,out]parserParser object.
[out]bufBuffer to store result.
[in]funcPredicate function.
[in]maxRequested length of data to read.
Returns
Length of data read, or 0 on error.

◆ M_parser_read_buf_mark()

size_t M_parser_read_buf_mark ( M_parser_t parser,
M_buf_t buf 
)

Read data from a marked position until the current parser position.

The marked position will be automatically cleared.

The data read will not be NULL terminated.

Parameters
[in,out]parserParser object.
[out]bufBuffer to store result.
Returns
number of bytes written to buffer or 0 on error.

◆ M_parser_read_parser()

M_parser_t * M_parser_read_parser ( M_parser_t parser,
size_t  len 
)

Create new parser from the current position for the given length from the current buffer, allocates a parser and advance. All data is copied into a new memory segment.

Parameters
[in,out]parserParser object.
[in]lenLength to read.
Returns
parser.

◆ M_parser_read_parser_until()

M_parser_t * M_parser_read_parser_until ( M_parser_t parser,
const unsigned char *  pat,
size_t  len,
M_bool  eat_pat 
)

Read data from the buffer until the specified sequence of bytes is encountered in the data stream. All data is copied into a new memory segment.

Put the resulting bytes in a newly allocated parser.

Parameters
[in,out]parserParser object.
[in]patSequence of bytes to search for.
[in]lenLength of pattern data.
[in]eat_patShould the sequence of bytes be consumed. Useful for ignoring data until end of comment.
Returns
parser.

◆ M_parser_read_parser_boundary()

M_parser_t * M_parser_read_parser_boundary ( M_parser_t parser,
const unsigned char *  pat,
size_t  len,
M_bool  eat_pat,
M_bool *  found 
)

Read data from the buffer until the specified sequence of bytes is encountered in the data stream. All data is copied into a new memory segment.

Put the resulting bytes in a newly allocated parser.

Parameters
[in,out]parserParser object.
[in]patSequence of bytes to search for.
[in]lenLength of pattern data.
[in]eat_patShould the sequence of bytes be consumed. Useful for ignoring data until end of comment.
[out]foundWas the full pat found. A partial boundy might still be in the parser if M_FALSE.
Returns
parser.

◆ M_parser_read_parser_charset()

M_parser_t * M_parser_read_parser_charset ( M_parser_t parser,
unsigned const char *  charset,
size_t  charset_len 
)

Read data from the buffer for as long as it matches one of the bytes in the given character set and advance. All data is copied into a new memory segment.

Put the resulting bytes in a newly allocated parser.

Parameters
[in,out]parserParser object.
[in]charsetArray of characters that are allowed, NULL terminated.
[in]charset_lenNumber of characters in the set.
Returns
parser.

◆ M_parser_read_parser_predicate()

M_parser_t * M_parser_read_parser_predicate ( M_parser_t parser,
M_parser_predicate_func  func 
)

Create new parser from the buffer for as long as it matches the given predicate function and advance. All data is copied into a new memory segment.

Put the resulting bytes in a newly allocated parser.

Parameters
[in,out]parserParser object.
[in]funcPredicate function.
Returns
parser.

◆ M_parser_read_parser_predicate_max()

M_parser_t * M_parser_read_parser_predicate_max ( M_parser_t parser,
M_parser_predicate_func  func,
size_t  max 
)

Create new parser from the buffer for as long as it matches the given predicate function up to a given maximum and advance. All data is copied into a new memory segment.

Put the resulting bytes in a newly allocated parser.

Parameters
[in,out]parserParser object.
[in]funcPredicate function.
[in]maxRequested length of data to read.
Returns
parser.

◆ M_parser_read_parser_chr_predicate()

M_parser_t * M_parser_read_parser_chr_predicate ( M_parser_t parser,
M_parser_predicate_func  func 
)

Create new parser from the buffer for as long as it matches the given predicate function and advance. All data is copied into a new memory segment.

Put the resulting bytes in a newly allocated parser.

Parameters
[in,out]parserParser object.
[in]funcPredicate function.
Returns
parser.

◆ M_parser_read_parser_chr_predicate_max()

M_parser_t * M_parser_read_parser_chr_predicate_max ( M_parser_t parser,
M_parser_predicate_func  func,
size_t  max 
)

Create new parser from the buffer for as long as it matches the given predicate function up to a given maximum and advance. All data is copied into a new memory segment.

Put the resulting bytes in a newly allocated parser.

Parameters
[in,out]parserParser object.
[in]funcPredicate function.
[in]maxRequested length of data to read.
Returns
parser.

◆ M_parser_read_parser_mark()

M_parser_t * M_parser_read_parser_mark ( M_parser_t parser)

Create new parser from a marked position until the current parser position, allocates a parser and advance. All data is copied into a new memory segment.

Parameters
[in,out]parserParser object.
Returns
parser.

◆ M_parser_read_stxetxlrc_message()

M_PARSER_FRAME_ERROR M_parser_read_stxetxlrc_message ( M_parser_t parser,
M_parser_t **  out,
M_uint32  lrc_frame_chars 
)

Read an STX, ETX, LRC wrapped message.

The first character in the parser must be an STX.

Parameters
[in,out]parserParser object.
[out]outParser object with result message.
[in]lrc_frame_charsFraming characters that should be included in LRC calculation.
Returns
result. On success and LRC calculation failure the message will be returned in the output parser. Otherwise the output parser's contents are undefined.

Results M_PARSER_FRAME_ERROR_NO_STX, M_PARSER_FRAME_ERROR_NO_ETX, and M_PARSER_FRAME_ERROR_NO_LRC will not advance the parser.

◆ M_parser_is_predicate()

M_bool M_parser_is_predicate ( const M_parser_t parser,
size_t  len,
M_parser_predicate_func  func 
)

Validate the parser matches the given predicate function.

If the input char data is signed, use M_parser_is_chr_predicate() instead.

Parameters
[in]parserParser object.
[in]lenLength to validate. If larger than the parser length the parser length is used.
[in]funcPredicate function.
Returns
M_TRUE if matching. Otherwise M_FALSE.

◆ M_parser_is_chr_predicate()

M_bool M_parser_is_chr_predicate ( const M_parser_t parser,
size_t  len,
M_chr_predicate_func  func 
)

Validate the parser matches the given chr predicate function.

If the input char data is unsigned, use M_parser_is_predicate() instead.

Parameters
[in]parserParser object.
[in]lenLength to validate. If larger than the parser length the parser length is used.
[in]funcChar predicate function.
Returns
M_TRUE if matching. Otherwise M_FALSE.

◆ M_parser_is_charset()

M_bool M_parser_is_charset ( const M_parser_t parser,
size_t  len,
const unsigned char *  charset,
size_t  charset_len 
)

Validate the parser matches the given character set.

Parameters
[in]parserParser object.
[in]lenLength to validate. If larger than the parser length the parser length is used.
[in]charsetCharacter set.
[in]charset_lenLength of given character set.
Returns
M_TRUE if matching. Otherwise M_FALSE.

◆ M_parser_is_str_charset()

M_bool M_parser_is_str_charset ( const M_parser_t parser,
size_t  len,
const char *  charset 
)

Validate the parser matches the given NULL-terminated charset.

Parameters
[in]parserParser object.
[in]lenLength to validate. If larger than the parser length the parser length is used.
[in]charsetCharacter set.
Returns
M_TRUE if matching. Otherwise M_FALSE.

◆ M_parser_is_not_predicate()

M_bool M_parser_is_not_predicate ( const M_parser_t parser,
size_t  len,
M_parser_predicate_func  func 
)

Validate the parser does not match the given predicate function.

If the input char data is signed, use M_parser_is_not_chr_predicate() instead.

Parameters
[in]parserParser object.
[in]lenLength to validate. If larger than the parser length the parser length is used.
[in]funcPredicate function.
Returns
M_TRUE if not matching. Otherwise M_FALSE. If parser is NULL, len is 0, or func is NULL, this will return M_TRUE.

◆ M_parser_is_not_chr_predicate()

M_bool M_parser_is_not_chr_predicate ( const M_parser_t parser,
size_t  len,
M_chr_predicate_func  func 
)

Validate the parser does not match the given chr predicate function.

If the input char data is unsigned, use M_parser_is_not_predicate() instead.

Parameters
[in]parserParser object.
[in]lenLength to validate. If larger than the parser length the parser length is used.
[in]funcChar predicate function.
Returns
M_TRUE if not matching. Otherwise M_FALSE. If parser is NULL, len is 0, or func is NULL, this will return M_TRUE.

◆ M_parser_is_not_charset()

M_bool M_parser_is_not_charset ( const M_parser_t parser,
size_t  len,
const unsigned char *  charset,
size_t  charset_len 
)

Validate the parser does not match the given character set.

Parameters
[in]parserParser object.
[in]lenLength to validate. If larger than the parser length the parser length is used.
[in]charsetCharacter set.
[in]charset_lenLength of given character set.
Returns
M_TRUE if not matching. Otherwise M_FALSE. If parser is NULL, len is 0, charset is NULL, or charset_len is 0, this will return M_TRUE.

◆ M_parser_is_not_str_charset()

M_bool M_parser_is_not_str_charset ( const M_parser_t parser,
size_t  len,
const char *  charset 
)

Validate the parser does not match the given NULL-terminated charset.

Parameters
[in]parserParser object.
[in]lenLength to validate. If larger than the parser length the parser length is used.
[in]charsetCharacter set.
Returns
M_TRUE if not matching. Otherwise M_FALSE. If parser is NULL, len is 0, or charset is NULL, this will return M_TRUE.

◆ M_parser_split()

M_parser_t ** M_parser_split ( M_parser_t parser,
unsigned char  delim,
size_t  maxcnt,
M_uint32  flags,
size_t *  num_output 
)

Split the data in the parser object by the delimiter specified into additional parser objects.

Parameters
[in,out]parserParser
[in]delimThe delimiter to split on
[in]maxcntMaximum number of objects to create, remaining data will be part of the last object. 0 if no maximum.
[in]flagsM_PARSER_SPLIT_FLAGS flags controlling behavior of parser
[out]num_outputThe number of parser objects output
Returns
array of parser objects or NULL on failure

◆ M_parser_split_pat()

M_parser_t ** M_parser_split_pat ( M_parser_t parser,
const unsigned char *  pat,
size_t  pat_len,
size_t  maxcnt,
M_uint32  flags,
size_t *  num_output 
)

Split the data in the parser object by the pattern specified into additional parser objects.

Parameters
[in,out]parserParser
[in]patSequence of bytes to search for.
[in]pat_lenLength of pattern data.
[in]maxcntMaximum number of objects to create, remaining data will be part of the last object. 0 if no maximum.
[in]flagsM_PARSER_SPLIT_FLAGS flags controlling behavior of parser
[out]num_outputThe number of parser objects output
Returns
array of parser objects or NULL on failure

◆ M_parser_split_str_pat()

M_parser_t ** M_parser_split_str_pat ( M_parser_t parser,
const char *  pat,
size_t  maxcnt,
M_uint32  flags,
size_t *  num_output 
)

Split the data in the parser object by the pattern specified into additional parser objects.

Parameters
[in,out]parserParser
[in]patString to search for.
[in]maxcntMaximum number of objects to create, remaining data will be part of the last object. 0 if no maximum.
[in]flagsM_PARSER_SPLIT_FLAGS flags controlling behavior of parser
[out]num_outputThe number of parser objects output
Returns
array of parser objects or NULL on failure

◆ M_parser_split_free()

void M_parser_split_free ( M_parser_t **  parsers,
size_t  cnt 
)

Free child parser objects returned from M_parser_split

Parameters
[in]parsersArray of parser objects
[in]cntCount of objects as returned from M_parser_split