libgslutil  1.2.3
Functions
Serialised string functions

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...
 

Detailed Description

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.

Function Documentation

◆ writes_i8()

char* writes_i8 ( char *  where,
uint8_t  i 
)

Write integer into memory string (8-bit).

Parameters
wherePointer to write position.
iInteger to write.
Returns
Pointer to position at which next write should occur.

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.

See also
writes_i16(), writes_i24(), writes_i32(), writes_i64()

◆ writes_str()

char* writes_str ( char *  where,
const char *  str 
)

Write null-terminated string into memory.

Parameters
wherePointer to write position.
strString to write.
Returns
Pointer to position at which next write should occur.

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.

◆ writes_mem()

char* writes_mem ( char *  where,
const char *  mem,
uint32_t  amt 
)

Write raw data into memory.

Parameters
wherePointer to write position.
memThe raw data to write.
amtThe number of bytes to write.
Returns
Pointer to position at which next write should occur.

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.

◆ reads_i8()

const char* reads_i8 ( const char *  where,
uint8_t *  i 
)

Read integer from memory (8-bit).

Parameters
wherePosition to read from.
[out]iInteger value read.
Returns
Position at which next read should occur.

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.

See also
read_i16(), read_i32(), read_i64()

◆ reads_str()

const char* reads_str ( const char *  where,
char *  str,
uint32_t  amt 
)

Read null-terminated string from memory.

Parameters
wherePosition to read from.
strPointer to array into which to read string data.
amtNumber of bytes available in str.
Returns
Position at which next read should occur.

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.

◆ reads_mem()

const char* reads_mem ( const char *  where,
char *  mem,
uint32_t  amt 
)

Read arbitrary data from memory.

Parameters
wherePosition to read from.
memPointer to array into which to read arbitrary data.
amtNumber of bytes to read.
Returns
Position at which next read should occur.

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.

◆ reads_stra()

const char* reads_stra ( const char *  where,
char **  str,
uint32_t *  amt 
)

Read null-terminated string from memory (allocate memory).

Parameters
wherePosition to read from.
[out]strPointer to newly-allocated string.
[out]amtSize of string (excluding terminating null, may be 0).
Returns
Position at which next read should occur.

Like reads_str(), only this version will allocate the required memory with safe_malloc().

◆ reads_mema()

const char* reads_mema ( const char *  where,
char **  mem,
uint32_t  amt 
)

Read arbitrary data from memory (allocate memory).

Parameters
wherePosition to read from.
[out]memPointer to newly-allocated array.
amtNumber of bytes to allocate and read.
Returns
Position at which next read should occur.

Like reads_mem(), only this version will allocate the required memory with safe_malloc().