Files
bluelib/serial/ctx.c

58 lines
2.0 KiB
C

#include <blue/serial.h>
#include <stdlib.h>
#include <string.h>
/*** PRIVATE DATA *************************************************************/
/*** PRIVATE FUNCTIONS ********************************************************/
/*** PUBLIC FUNCTIONS *********************************************************/
/*** PUBLIC ALIAS FUNCTIONS ***************************************************/
/*** VIRTUAL FUNCTIONS ********************************************************/
static void serial_ctx_init(b_object *obj, void *priv)
{
b_serial_ctx_data *data = b_object_get_protected(obj, B_TYPE_SERIAL_CTX);
data->ctx_streambuf = b_stream_buffer_create_dynamic(2048);
}
static void serial_ctx_fini(b_object *obj, void *priv)
{
b_serial_ctx_data *data = b_object_get_protected(obj, B_TYPE_SERIAL_CTX);
b_stream_buffer_unref(data->ctx_streambuf);
}
/*** CLASS DEFINITION *********************************************************/
B_TYPE_CLASS_DEFINITION_BEGIN(b_serial_ctx)
B_TYPE_CLASS_INTERFACE_BEGIN(b_object, B_TYPE_OBJECT)
B_INTERFACE_ENTRY(to_string) = NULL;
B_TYPE_CLASS_INTERFACE_END(b_object, B_TYPE_OBJECT)
B_TYPE_CLASS_DEFINITION_END(b_serial_ctx)
B_TYPE_DEFINITION_BEGIN(b_serial_ctx)
B_TYPE_ID(0xc7c1039a, 0xf397, 0x4fda, 0xb473, 0x4d86fec85384);
B_TYPE_CLASS(b_serial_ctx_class);
B_TYPE_INSTANCE_PROTECTED(b_serial_ctx_data);
B_TYPE_INSTANCE_INIT(serial_ctx_init);
B_TYPE_INSTANCE_FINI(serial_ctx_fini);
B_TYPE_DEFINITION_END(b_serial_ctx)
/*** ITERATOR FUNCTIONS *******************************************************/
enum b_status b_serial_ctx_serialise(
b_serial_ctx *ctx, b_object *src, b_stream *dest, enum b_serial_flags flags)
{
B_CLASS_DISPATCH_VIRTUAL(
b_serial_ctx, B_TYPE_SERIAL_CTX, B_ERR_NOT_SUPPORTED,
s_serialise, ctx, src, dest, flags);
}
enum b_status b_serial_ctx_deserialise(
b_serial_ctx *ctx, b_stream *src, b_object **dest, enum b_serial_flags flags)
{
B_CLASS_DISPATCH_VIRTUAL(
b_serial_ctx, B_TYPE_SERIAL_CTX, B_ERR_NOT_SUPPORTED,
s_deserialise, ctx, src, dest, flags);
}