ubjsc  0.5
Enterprise-grade C library for manipulating UBJSON
Data Structures | Typedefs | Functions
ubjs_writer.h File Reference

Bytestream writer and pretty-printer of ubjson primitives. More...

#include "ubjs_common.h"
#include "ubjs_library.h"
#include "ubjs_primitives.h"
Include dependency graph for ubjs_writer.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  ubjs_writer_context
 User-provided context - callbacks and userdata. More...
 

Typedefs

typedef struct ubjs_writer ubjs_writer
 Writer itself.
 
typedef struct ubjs_writer_context ubjs_writer_context
 User-provided context - callbacks and userdata.
 
typedef void(* ubjs_writer_context_would_write) (ubjs_writer_context *this, uint8_t *data, unsigned int length)
 Callback when writer produced bytes out of a primitive. More...
 
typedef void(* ubjs_writer_context_would_print) (ubjs_writer_context *this, char *data, unsigned int length)
 Callback when writer produced pretty-printed version of a primitive. More...
 
typedef void(* ubjs_writer_context_free) (ubjs_writer_context *this)
 Callback when writer is about to be free-d. More...
 

Functions

UBJS_EXPORT ubjs_result ubjs_writer_new (ubjs_library *lib, ubjs_writer **pthis, ubjs_writer_context *context)
 Creates new writer. More...
 
UBJS_EXPORT ubjs_result ubjs_writer_free (ubjs_writer **pthis)
 Frees the writer. More...
 
UBJS_EXPORT ubjs_result ubjs_writer_get_context (ubjs_writer *this, ubjs_writer_context **pcontext)
 Gets user context from the writer. More...
 
UBJS_EXPORT ubjs_result ubjs_writer_write (ubjs_writer *this, ubjs_prmtv *object)
 Writes a bytestream out of a primitive. More...
 
UBJS_EXPORT ubjs_result ubjs_writer_print (ubjs_writer *this, ubjs_prmtv *object)
 Pretty-prints out of a primitive. More...
 

Detailed Description

Bytestream writer and pretty-printer of ubjson primitives.

This file describes ubjs_writer structure, that writes ubjson primitives to bytestreams and also pretty-prints'em.

Since
0.2

Typedef Documentation

§ ubjs_writer_context_free

typedef void(* ubjs_writer_context_free) (ubjs_writer_context *this)

Callback when writer is about to be free-d.

Here you can cleanup your userdata.

Parameters
thisContext object you passed to ubjs_writer_new.

§ ubjs_writer_context_would_print

typedef void(* ubjs_writer_context_would_print) (ubjs_writer_context *this, char *data, unsigned int length)

Callback when writer produced pretty-printed version of a primitive.

Parameters
thisContext object you passed to ubjs_writer_new.
dataOutgoing printf()-ready data.
lenLength of the data.

§ ubjs_writer_context_would_write

typedef void(* ubjs_writer_context_would_write) (ubjs_writer_context *this, uint8_t *data, unsigned int length)

Callback when writer produced bytes out of a primitive.

Parameters
thisContext object you passed to ubjs_writer_new.
dataOutgoing data.
lenLength of the data.

Function Documentation

§ ubjs_writer_free()

UBJS_EXPORT ubjs_result ubjs_writer_free ( ubjs_writer **  pthis)

Frees the writer.

The call to context->free will occur here. After this, *pthis will be equal to 0.

Parameters
pthisPointer to the writer.
Returns
UR_ERROR if pthis is 0, else UR_OK.

References UR_ERROR, and UR_OK.

§ ubjs_writer_get_context()

UBJS_EXPORT ubjs_result ubjs_writer_get_context ( ubjs_writer this,
ubjs_writer_context **  pcontext 
)

Gets user context from the writer.

Parameters
thisWriter.
pcontextPointer to where put user context.
Returns
UR_ERROR if any of this/pcontext is 0, else UR_OK.

References UR_ERROR, and UR_OK.

§ ubjs_writer_new()

UBJS_EXPORT ubjs_result ubjs_writer_new ( ubjs_library lib,
ubjs_writer **  pthis,
ubjs_writer_context context 
)

Creates new writer.

Parameters
libLibrary handle.
pthisPointer to where put newly created writer.
contextUser context.
Returns
UR_ERROR if any of lib/pthis/context/context->free is 0, else UR_OK.
Since
0.4

References ubjs_library::alloc_f, ubjs_writer_context::free, UR_ERROR, and UR_OK.

§ ubjs_writer_print()

UBJS_EXPORT ubjs_result ubjs_writer_print ( ubjs_writer this,
ubjs_prmtv object 
)

§ ubjs_writer_write()

UBJS_EXPORT ubjs_result ubjs_writer_write ( ubjs_writer this,
ubjs_prmtv object 
)

Writes a bytestream out of a primitive.

This produces the callback to context->would_write with fresh bytestream.

Parameters
thisWriter.
objectPrimitive.
Returns
UR_ERROR if any of this/object is 0, else UR_OK.

References UR_ERROR, and UR_OK.