libgslutil
1.2.3
|
Functions | |
char * | writes_i8 (char *where, uint8_t i)) |
Write integer into memory string (8-bit). More... | |
char * | writes_i16 (char *where, uint16_t i)) |
Write integer into memory string (16-bit). | |
char * | writes_i24 (char *where, uint32_t i)) |
Write integer into memory string (24-bit). | |
char * | writes_i32 (char *where, uint32_t i)) |
Write integer into memory string (32-bit). | |
char * | writes_i64 (char *where, uint64_t i)) |
Write integer into memory string (64-bit). | |
char * | writes_f32 (char *where, float f)) |
Write a 32-bit IEEE floating point. | |
char * | writes_f64 (char *where, double f)) |
Write a 64-bit IEEE floating point. | |
char * | writes_str (char *where, const char *str)) |
Write null-terminated string into memory. More... | |
char * | writes_mem (char *where, const char *mem, uint32_t amt)) |
Write raw data into memory. More... | |
const char * | reads_i8 (const char *where, uint8_t *i)) |
Read integer from memory (8-bit). More... | |
const char * | reads_i16 (const char *where, uint16_t *i)) |
Read integer from memory (16-bit). | |
const char * | reads_i24 (const char *where, uint32_t *i)) |
Read integer from memory (24-bit). | |
const char * | reads_i24s (const char *where, int32_t *i)) |
Read integer from memory (24-bit), and sign extend it to 32-bit. | |
const char * | reads_i32 (const char *where, uint32_t *i)) |
Read integer from memory (32-bit). | |
const char * | reads_i64 (const char *where, uint64_t *i)) |
Read integer from memory (64-bit). | |
const char * | reads_f32 (const char *where, float *f)) |
Read a 32-bit IEEE floating point from memory. | |
const char * | reads_f64 (const char *where, double *f)) |
Read a 64-bit IEEE floating point from memory. | |
const char * | reads_str (const char *where, char *str, uint32_t amt)) |
Read null-terminated string from memory. More... | |
const char * | reads_mem (const char *where, char *mem, uint32_t amt)) |
Read arbitrary data from memory. More... | |
const char * | reads_stra (const char *where, char **str, uint32_t *amt)) |
Read null-terminated string from memory (allocate memory). More... | |
const char * | reads_mema (const char *where, char **mem, uint32_t amt)) |
Read arbitrary data from memory (allocate memory). More... | |
This set of functions is used to perform architecture-independent reads/writes from/to memory. The functions each take a pointer to memory (as char*
), and return a pointer to the next location in memory after they have read their required data.
char* writes_i8 | ( | char * | where, |
uint8_t | i | ||
) |
Write integer into memory string (8-bit).
where | Pointer to write position. |
i | Integer to write. |
Writes an integer, in an architecture-independent manner, into the memory buffer at where. It is the caller's responsibility to ensure there is enough space.
char* writes_str | ( | char * | where, |
const char * | str | ||
) |
Write null-terminated string into memory.
where | Pointer to write position. |
str | String to write. |
Writes a string, in an architecture-independent manner, into the memory buffer at where. It is the caller's responsibility to ensure there is enough space (length of string + 4 bytes). The length of the string is written into memory as a prefix so that reading can be efficient. Written as length (32-bit integer) followed by data, without terminating null.
char* writes_mem | ( | char * | where, |
const char * | mem, | ||
uint32_t | amt | ||
) |
Write raw data into memory.
where | Pointer to write position. |
mem | The raw data to write. |
amt | The number of bytes to write. |
Writes a set of bytes, in an architecture-independent manner, into the buffer at where. It is the caller's responsibility to ensure there is enough space (amt bytes). The length is not recorded, so it must either be written first or fixed in the reader and writer.
const char* reads_i8 | ( | const char * | where, |
uint8_t * | i | ||
) |
Read integer from memory (8-bit).
where | Position to read from. | |
[out] | i | Integer value read. |
This function reads an integer written with writes_i8() or writem_i8(). It works in an architecture-independent manner. It returns a pointer to the next unused data in the buffer. It is the caller's responsibility to ensure the buffer contains enough data.
const char* reads_str | ( | const char * | where, |
char * | str, | ||
uint32_t | amt | ||
) |
Read null-terminated string from memory.
where | Position to read from. |
str | Pointer to array into which to read string data. |
amt | Number of bytes available in str. |
This function reads a string written with writes_str() or writem_str(). It works in an architecture-independent manner. It returns a pointer to the next unused data in the buffer. It is the caller's responsibility to ensure the buffer contains enough data.
If the string in the buffer is too large to fit into str, it is truncated. However, in any case, the output string will always be null terminated and the return value will always point to the correct location.
const char* reads_mem | ( | const char * | where, |
char * | mem, | ||
uint32_t | amt | ||
) |
Read arbitrary data from memory.
where | Position to read from. |
mem | Pointer to array into which to read arbitrary data. |
amt | Number of bytes to read. |
This function reads arbitrary data, possibly written with writes_mem() or writem_mem(). It works in an architecture-independent manner. It returns a pointer to the next unused data in the buffer. It is the caller's responsibility to ensure the buffer contains enough data.
const char* reads_stra | ( | const char * | where, |
char ** | str, | ||
uint32_t * | amt | ||
) |
Read null-terminated string from memory (allocate memory).
where | Position to read from. | |
[out] | str | Pointer to newly-allocated string. |
[out] | amt | Size of string (excluding terminating null, may be 0). |
Like reads_str(), only this version will allocate the required memory with safe_malloc().
const char* reads_mema | ( | const char * | where, |
char ** | mem, | ||
uint32_t | amt | ||
) |
Read arbitrary data from memory (allocate memory).
where | Position to read from. | |
[out] | mem | Pointer to newly-allocated array. |
amt | Number of bytes to allocate and read. |
Like reads_mem(), only this version will allocate the required memory with safe_malloc().