libgslutil  1.2.3
Functions
Read serialised string using template

Functions

int reads_template (const char *ser, size_t len, size_t *used, const char *tpl,...)
 Read serialised string using template. More...
 
int readm_template (struct membuf_t *buf, const char *tpl,...)
 Read serialised memory buffer using template. More...
 
int reads_templatev (const char *ser, size_t len, size_t *used, const char *tpl, va_list va)
 Read serialised string using template [varargs]. More...
 

Detailed Description

A set of high-level routines which use simple string templates to parse a serialised bitstring, unpacking the results into a variable set of arguments passed using the stdarg mechanism.

Template string format

Each character in the template string specifies a variable to be converted. Each character must correspond to at least one argument in the variable argument list.

Conversion characterDescriptionArguments
18-bit integeruint8_t*
216-bit integeruint16_t*
432-bit integeruint32_t*
864-bit integeruint64_t*
f32-bit floatfloat*
d64-bit doubledouble*
sStringsize_t*, char**
SSize-limited stringsize_t, size_t*, char**
mMemorysize_t, void*

The basic scalar types are trivial; each character corresponds to one argument, which is a pointer to the memory where the result should be stored after conversion.

The string type takes a pointer to a size_t argument, which is set to the length of the string (excluding terminating null). The char** argument is set to point to a newly-allocated buffer which contains the string (with an extra null terminator). The size-limited string type checks its first size_t argument and does not perform the conversion if the recorded size string exceeds this value.

The memory type takes a size_t argument, which is the number of bytes to read, and a pointer to a pre-allocated buffer into which the memory should be copied.

Function Documentation

◆ reads_template()

int reads_template ( const char *  ser,
size_t  len,
size_t *  used,
const char *  tpl,
  ... 
)

Read serialised string using template.

Parameters
serPointer to the serialised string.
lenLength of serialised string, in bytes.
[out]usedSet to the number of bytes read from ser.
tplTemplate string (see format).
Returns
Number of items parsed.

This function uses the template string template to parse the serialised string ser. It will never read more than len bytes from ser. It sets *used to the number of bytes actually used during the read operation, and returns the number of items successfully read.

◆ readm_template()

int readm_template ( struct membuf_t *  buf,
const char *  tpl,
  ... 
)

Read serialised memory buffer using template.

Parameters
bufMemory buffer.
tplTemplate string (see format).
Returns
Number of items parsed.

This function uses the template string template to parse the serialised memory buffer buf. It will consume any memory read from buf before returning. It returns the number of items successfully read. Implemented as a simple wrapper around reads_template().

◆ reads_templatev()

int reads_templatev ( const char *  ser,
size_t  len,
size_t *  used,
const char *  tpl,
va_list  va 
)

Read serialised string using template [varargs].

Parameters
serPointer to the serialised string.
lenLength of serialised string, in bytes.
[out]usedSet to the number of bytes read from ser.
tplTemplate string (see format).
vaVariable argument list.
Returns
Number of items parsed.

This function uses the template string template to parse the serialised string ser. It will never read more than len bytes from ser. It sets *used to the number of bytes actually used during the read operation, and returns the number of items successfully read.