Serializer

General programmable serialization functions. (A shared interface to various reading/writing to/from different inputs/outputs)

#include <serializer.h>

Serializer Structure (struct serializer)

struct serializer
void *serializer.data
size_t (*serializer.read)(void*, void*, size_t)
size_t (*serializer.write)(void*, const void*, size_t)
int64_t (*serializer.seek)(void*, int64_t, enum serialize_seek_type)
int64_t (*serializer.get_pos)(void*)

Serializer Inline Functions

size_t s_read(struct serializer *s, void *data, size_t size)

size_t s_write(struct serializer *s, const void *data, size_t size)

size_t serialize(struct serializer *s, void *data, size_t len)

int64_t serializer_seek(struct serializer *s, int64_t offset, enum serialize_seek_type seek_type)

int64_t serializer_get_pos(struct serializer *s)

void s_w8(struct serializer *s, uint8_t u8)

void s_wl16(struct serializer *s, uint16_t u16)

void s_wl32(struct serializer *s, uint32_t u32)

void s_wl64(struct serializer *s, uint64_t u64)

void s_wlf(struct serializer *s, float f)

void s_wld(struct serializer *s, double d)

void s_wb16(struct serializer *s, uint16_t u16)

void s_wb24(struct serializer *s, uint32_t u24)

void s_wb32(struct serializer *s, uint32_t u32)

void s_wb64(struct serializer *s, uint64_t u64)

void s_wbf(struct serializer *s, float f)

void s_wbd(struct serializer *s, double d)

Array Output Serializer

Provides an output serializer used with dynamic arrays.

Changed in version 30.2: Array output serializer now supports seeking.

#include <util/array-serializer.h>

Array Output Serializer Structure (struct array_output_data)

struct array_output_data
DARRAY(uint8_t) array_output_data.bytes

Array Output Serializer Functions

void array_output_serializer_init(struct serializer *s, struct array_output_data *data)

void array_output_serializer_free(struct array_output_data *data)

void array_output_serializer_reset(struct array_output_data *data)

Resets serializer without freeing data.

Added in version 30.2.


File Input/Output Serializers

Provides file reading/writing serializers.

#include <util/file-serializer.h>

File Input Serializer Functions

bool file_input_serializer_init(struct serializer *s, const char *path)

Initializes a file input serializer.

Returns:

true if file opened successfully, false otherwise


void file_input_serializer_free(struct serializer *s)

Frees a file input serializer.


File Output Serializer Functions

bool file_output_serializer_init(struct serializer *s, const char *path)

Initializes a file output serializer.

Returns:

true if file created successfully, false otherwise


bool file_output_serializer_init_safe(struct serializer *s, const char *path, const char *temp_ext)

Initializes and safely writes to a temporary file (determined by the temporary extension) until freed.

Returns:

true if file created successfully, false otherwise


void file_output_serializer_free(struct serializer *s)

Frees the file output serializer and saves the file.


Buffered File Output Serializer

Provides a buffered file serializer that writes data asynchronously to prevent stalls due to slow disk I/O.

Writes will only block when the buffer is full.

The buffer and chunk size are configurable with the defaults being 256 MiB and 1 MiB respectively.

Added in version 30.2.

#include <util/buffered-file-serializer.h>

Buffered File Output Serializer Functions

bool buffered_file_serializer_init_defaults(struct serializer *s, const char *path)

Initializes a buffered file output serializer with default buffer and chunk sizes.

Returns:

true if file created successfully, false otherwise


bool buffered_file_serializer_init(struct serializer *s, const char *path, size_t max_bufsize, size_t chunk_size)

Initialize buffered writer with specified buffer and chunk sizes. Setting either to 0 will use the default value.

Returns:

true if file created successfully, false otherwise


void buffered_file_serializer_free(struct serializer *s)

Frees the file output serializer and saves the file. Will block until I/O thread completes outstanding writes.