C Serialize API

Functions

static int serialize_ascii_table(const seri_t s, char *buf, const size_t buf_siz, int *args_used, va_list ap)

Serialize arguments to create a table row.

Parameters
  • s: seri_t Structure sepcifying how to serialize arguments.
  • buf: character pointer to pointer to memory where serialized message should be stored.
  • buf_siz: size_t Size of memory allocated to buf.
  • args_used: int Number of arguments formatted.
  • ap: va_list Arguments to be formatted. returns: int The length of the serialized message or -1 if there is an error.

static int deserialize_ascii_table(const seri_t s, const char *buf, const size_t buf_siz, va_list ap)

Deserialize table row to populate arguments.

Parameters
  • s: seri_t Structure sepcifying how to deserialize message.
  • buf: character pointer to serialized message.
  • buf_siz: size_t Size of buf.
  • ap: va_list Arguments to be parsed from message. returns: int The number of populated arguments. -1 indicates an error.

static int serialize_ascii_table_array(const seri_t s, char *buf, const size_t buf_siz, int *args_used, va_list ap)

Serialize column arrays to create table.

Parameters
  • s: seri_t Structure sepcifying how to serialize arguments.
  • buf: character pointer to pointer to memory where serialized message should be stored.
  • buf_siz: size_t Size of memory allocated to buf.
  • args_used: int Number of arguments formatted.
  • ap: va_list Arguments to be formatted. These should be pointers to arrays, one for each column in the table. The first argument should be the number of rows in each column. returns: int The length of the serialized message or -1 if there is an error.

static int deserialize_ascii_table_array(const seri_t s, const char *buf, const size_t buf_siz, va_list ap)

Deserialize table to populate column arrays.

Parameters
  • s: seri_t Structure sepcifying how to deserialize message.
  • buf: character pointer to serialized message.
  • buf_siz: size_t Size of buf.
  • ap: va_list Pointers to pointers where column arrays should be stored. These should not be allocated prior to passing them as they will be allocated. returns: int The number of populated arguments. -1 indicates an error.

Functions

static int serialize_format(const seri_t s, char *buf, const size_t buf_siz, int *args_used, va_list ap)

Serialize arguments to create a message.

Parameters
  • s: seri_t Structure sepcifying how to serialize arguments.
  • buf: character pointer to pointer to memory where serialized message should be stored.
  • buf_siz: size_t Size of memory allocated to buf.
  • args_used: int Number of arguments formatted.
  • ap: va_list Arguments to be formatted. returns: int The length of the serialized message or -1 if there is an error.

static int deserialize_format(const seri_t s, const char *buf, const size_t buf_siz, va_list ap)

Deserialize message to populate arguments.

Parameters
  • s: seri_t Structure sepcifying how to deserialize message.
  • buf: character pointer to serialized message.
  • buf_siz: size_t Size of buf.
  • ap: va_list Arguments to be parsed from message. returns: int The number of populated arguments. -1 indicates an error.

Typedefs

typedef struct obj_t obj_t

Obj structure.

Functions

static obj_t init_obj()

Initialize empty obj structure.

Return
obj_t Obj structure.

static void free_obj(obj_t *p)

Free obj structure.

Parameters
  • p: *obj_t Pointer to obj structure.

static int alloc_obj(obj_t *p, int nvert, int nface, int ntexc, int nnorm, int do_color)

Allocate obj structure.

Return
int 0 if successful, -1 otherwise.
Parameters
  • p: *obj_t Pointer to obj structure that should be allocated.
  • nvert: int Number of vertices that should be allocated for.
  • nface: int Number of faces that should be allocated for.
  • ntexc: int Number of texcoords that should be allocated for.
  • nnorm: int Number of normals that should be allocated for.
  • do_color: int 1 if vertex colors should be allocated, 0 if not.

static int serialize_obj(const seri_t s, char *buf, const size_t buf_size, int *args_used, va_list ap)

Serialize obj information to create a message.

Return
: int The length of the serialized message or -1 if there is an error.
Parameters
  • s: seri_t Structure sepcifying how to serialize arguments.
  • buf: character pointer to memory where serialized message should be stored.
  • buf_size: size_t Size of memory allocated to buf.
  • args_used: int Number of arguments formatted.
  • ap: va_list Arguments to be formatted.

static int deserialize_obj(const seri_t s, const char *buf, const size_t buf_siz, va_list ap)

Deserialize message to populate obj structure.

Parameters
  • s: seri_t Structure sepcifying how to deserialize message.
  • buf: character pointer to serialized message.
  • buf_siz: size_t Size of buf.
  • ap: va_list Arguments to be parsed from message. returns: int The number of populated arguments. -1 indicates an error.

struct obj_t
#include <ObjSerialize.h>

Obj structure.

Public Members

int nvert

Number of vertices.

int nface

Number faces.

float **vertices

X, Y, Z positions of vertices.

int **faces

Indices of the vertices composing each face.

int **vertex_colors

RGB colors of each vertex.

char material

Material that should be used for faces.

int ntexc

Number of texture coordinates.

int nnorm

Number of normals.

float **texcoords

Texture coordinates.

float **normals

X, Y, Z direction of normals.

int **face_texcoords

Indices of texcoords for each face.

int **face_normals

Indices of normals for each face.

Typedefs

typedef struct ply_t ply_t

Ply structure.

Functions

static ply_t init_ply()

Initialize empty ply structure.

Return
ply_t Ply structure.

static void free_ply(ply_t *p)

Free ply structure.

Parameters
  • p: *ply_t Pointer to ply structure.

static int alloc_ply(ply_t *p, int nvert, int nface, int do_color)

Allocate ply structure.

Return
int 0 if successful, -1 otherwise.
Parameters
  • p: *ply_t Pointer to ply structure that should be allocated.
  • nvert: int Number of vertices that should be allocated for.
  • nface: int Number of faces that should be allocated for.
  • do_color: int 1 if vertex colors should be allocated, 0 if not.

static int serialize_ply(const seri_t s, char *buf, const size_t buf_size, int *args_used, va_list ap)

Serialize ply information to create a message.

Return
: int The length of the serialized message or -1 if there is an error.
Parameters
  • s: seri_t Structure sepcifying how to serialize arguments.
  • buf: character pointer to memory where serialized message should be stored.
  • buf_size: size_t Size of memory allocated to buf.
  • args_used: int Number of arguments formatted.
  • ap: va_list Arguments to be formatted.

static int deserialize_ply(const seri_t s, const char *buf, const size_t buf_siz, va_list ap)

Deserialize message to populate ply structure.

Parameters
  • s: seri_t Structure sepcifying how to deserialize message.
  • buf: character pointer to serialized message.
  • buf_siz: size_t Size of buf.
  • ap: va_list Arguments to be parsed from message. returns: int The number of populated arguments. -1 indicates an error.

struct ply_t
#include <PlySerialize.h>

Ply structure.

Public Members

int nvert

Number of vertices.

int nface

Number faces.

float **vertices

X, Y, Z positions of vertices.

int **faces

Indices of the vertices composing each face.

int **vertex_colors

RGB colors of each vertex.

int *nvert_in_face

Number of vertices in each face.

Typedefs

typedef enum seri_enum seri_type
typedef struct seri_t seri_t

Serializer structure.

Enums

enum seri_enum

Serializer types.

Values:

DIRECT_SERI
FORMAT_SERI
ARRAY_SERI
ASCII_TABLE_SERI
ASCII_TABLE_ARRAY_SERI
PLY_SERI
OBJ_SERI

Functions

static int serialize_direct(const seri_t s, char *buf, const size_t buf_siz, int *args_used, va_list ap)

Serialize arguments to create a message.

Parameters
  • s: seri_t Structure sepcifying how to serialize arguments.
  • buf: character pointer to memory where serialized message should be stored.
  • buf_siz: size_t Size of memory allocated to buf.
  • args_used: int Number of arguments formatted.
  • ap: va_list Arguments to be formatted. returns: int The length of the serialized message or -1 if there is an error.

static int deserialize_direct(const seri_t s, const char *buf, const size_t buf_siz, va_list ap)

Deserialize message to populate arguments.

Parameters
  • s: seri_t Structure sepcifying how to deserialize message.
  • buf: character pointer to serialized message.
  • buf_siz: size_t Size of buf.
  • ap: va_list Arguments to be parsed from message. returns: int The number of populated arguments. -1 indicates an error.

struct seri_t
#include <SerializeBase.h>

Serializer structure.

Public Members

seri_type type

Serializer type.

void *info

Pointer to any extra info serializer requires.

JSON type.

size_t size_info

Size of allocate space for info.

Typedefs

typedef struct seri_t seri_t

Serializer structure.

Functions

static seri_t empty_serializer()

Create an empty serializer structure.

Return
seri_t Empty serializer.

static int free_serializer(seri_t *s)

Free serializer.

Return
int -1 if there was an error, 0 otherwise.
Parameters
  • s: seri_t* Serializer that should be freed.

static int update_precision(seri_t *s, const char *type, void *info)

Update serializer with precision from provided information.

Return
int -1 if there is an error, 0 otherwise.
Parameters
  • s: seri_t * Address of serializer that should be updated. If NULL, one is created.
  • type: char* Type that should be updated for the serializer.
  • info: void * Information about serializer type. Assumes that any necessary copy has taken place and mearly assigns the pointer.

static int update_serializer(seri_t *s, const char *type, void *info)

Update serializer with provided information.

Return
int -1 if there is an error, 0 otherwise.
Parameters
  • s: seri_t * Address of serializer that should be updated. If NULL, one is created.
  • type: char* Type that should be updated for the serializer.
  • info: void * Information about serializer type. Assumes that any necessary copy has taken place and mearly assigns the pointer.

static seri_t *init_serializer(const char *type, void *info)

Initialize serialier.

Return
seri_t* Address of serializer.
Parameters
  • type: char* Type that should be updated for the serializer.
  • info: void * Information for the serializer.

static int serialize(const seri_t s, char **buf, size_t *buf_siz, const int allow_realloc, size_t *nargs, va_list_t ap)

Serialize arguments to create a message.

Parameters
  • s: seri_t Structure sepcifying how to serialize arguments.
  • buf: character pointer to pointer to memory where serialized message should be stored.
  • buf_siz: size_t Size of memory allocated to buf.
  • allow_realloc: int If 1, buf will be realloced if it is not big enough to hold the serialized emssage. If 0, an error will be returned.
  • nargs: int Number of arguments remaining in argument list.
  • ap: va_list Arguments to be formatted. returns: int The length of the serialized message or -1 if there is an error.

static int deserialize(const seri_t s, const char *buf, const size_t buf_siz, const int allow_realloc, size_t *nargs, va_list_t ap)

Deserialize message to populate arguments.

Parameters
  • s: seri_t Structure sepcifying how to deserialize message.
  • buf: character pointer to serialized message.
  • buf_siz: size_t Size of buf.
  • allow_realloc: int If 1, variables being filled are assumed to be pointers to pointers for heap memory. If 0, variables are assumed to be pointers to stack memory. If allow_realloc is set to 1, but stack variables are passed, a segfault can occur.
  • nargs: int Number of arguments remaining in argument list.
  • ap: va_list Arguments to be parsed from message. returns: int The number of populated arguments. -1 indicates an error.