libgslutil
1.2.3
|
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... | |
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.
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 character | Description | Arguments |
1 | 8-bit integer | uint8_t* |
2 | 16-bit integer | uint16_t* |
4 | 32-bit integer | uint32_t* |
8 | 64-bit integer | uint64_t* |
f | 32-bit float | float* |
d | 64-bit double | double* |
s | String | size_t*, char** |
S | Size-limited string | size_t, size_t*, char** |
m | Memory | size_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.
int reads_template | ( | const char * | ser, |
size_t | len, | ||
size_t * | used, | ||
const char * | tpl, | ||
... | |||
) |
Read serialised string using template.
ser | Pointer to the serialised string. | |
len | Length of serialised string, in bytes. | |
[out] | used | Set to the number of bytes read from ser. |
tpl | Template string (see format). |
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.
int readm_template | ( | struct membuf_t * | buf, |
const char * | tpl, | ||
... | |||
) |
Read serialised memory buffer using template.
buf | Memory buffer. |
tpl | Template string (see format). |
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().
int reads_templatev | ( | const char * | ser, |
size_t | len, | ||
size_t * | used, | ||
const char * | tpl, | ||
va_list | va | ||
) |
Read serialised string using template [varargs].
ser | Pointer to the serialised string. | |
len | Length of serialised string, in bytes. | |
[out] | used | Set to the number of bytes read from ser. |
tpl | Template string (see format). | |
va | Variable argument list. |
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.