YAJL 1.0.12
Data Structures | Typedefs | Enumerations | Functions
yajl_gen.h File Reference
#include <yajl/yajl_common.h>

Go to the source code of this file.

Data Structures

struct  yajl_gen_config

Typedefs

typedef struct yajl_gen_t * yajl_gen
typedef void(* yajl_print_t )(void *ctx, const char *str, unsigned int len)

Enumerations

enum  yajl_gen_status {
  yajl_gen_status_ok = 0, yajl_gen_keys_must_be_strings, yajl_max_depth_exceeded, yajl_gen_in_error_state,
  yajl_gen_generation_complete, yajl_gen_invalid_number, yajl_gen_no_buf
}

Functions

YAJL_API yajl_gen yajl_gen_alloc (const yajl_gen_config *config, const yajl_alloc_funcs *allocFuncs)
YAJL_API yajl_gen yajl_gen_alloc2 (const yajl_print_t callback, const yajl_gen_config *config, const yajl_alloc_funcs *allocFuncs, void *ctx)
YAJL_API void yajl_gen_free (yajl_gen handle)
YAJL_API yajl_gen_status yajl_gen_integer (yajl_gen hand, long int number)
YAJL_API yajl_gen_status yajl_gen_double (yajl_gen hand, double number)
YAJL_API yajl_gen_status yajl_gen_number (yajl_gen hand, const char *num, unsigned int len)
YAJL_API yajl_gen_status yajl_gen_string (yajl_gen hand, const unsigned char *str, unsigned int len)
YAJL_API yajl_gen_status yajl_gen_null (yajl_gen hand)
YAJL_API yajl_gen_status yajl_gen_bool (yajl_gen hand, int boolean)
YAJL_API yajl_gen_status yajl_gen_map_open (yajl_gen hand)
YAJL_API yajl_gen_status yajl_gen_map_close (yajl_gen hand)
YAJL_API yajl_gen_status yajl_gen_array_open (yajl_gen hand)
YAJL_API yajl_gen_status yajl_gen_array_close (yajl_gen hand)
YAJL_API yajl_gen_status yajl_gen_get_buf (yajl_gen hand, const unsigned char **buf, unsigned int *len)
YAJL_API void yajl_gen_clear (yajl_gen hand)

Detailed Description

Interface to YAJL's JSON generation facilities.


Typedef Documentation

typedef struct yajl_gen_t* yajl_gen

an opaque handle to a generator

typedef void(* yajl_print_t)(void *ctx, const char *str, unsigned int len)

a callback used for "printing" the results.


Enumeration Type Documentation

generator status codes

Enumerator:
yajl_gen_status_ok 

no error

yajl_gen_keys_must_be_strings 

at a point where a map key is generated, a function other than yajl_gen_string was called

yajl_max_depth_exceeded 

YAJL's maximum generation depth was exceeded. see YAJL_MAX_DEPTH

yajl_gen_in_error_state 

A generator function (yajl_gen_XXX) was called while in an error state

yajl_gen_generation_complete 

A complete JSON document has been generated

yajl_gen_invalid_number 

yajl_gen_double was passed an invalid floating point value (infinity or NaN).

yajl_gen_no_buf 

A print callback was passed in, so there is no internal buffer to get from


Function Documentation

YAJL_API yajl_gen yajl_gen_alloc ( const yajl_gen_config config,
const yajl_alloc_funcs allocFuncs 
)

allocate a generator handle

Parameters:
configa pointer to a structure containing parameters which configure the behavior of the json generator
allocFuncsan optional pointer to a structure which allows the client to overide the memory allocation used by yajl. May be NULL, in which case malloc/free/realloc will be used.
Returns:
an allocated handle on success, NULL on failure (bad params)
YAJL_API yajl_gen yajl_gen_alloc2 ( const yajl_print_t  callback,
const yajl_gen_config config,
const yajl_alloc_funcs allocFuncs,
void *  ctx 
)

allocate a generator handle that will print to the specified callback rather than storing the results in an internal buffer.

Parameters:
callbacka pointer to a printer function. May be NULL in which case, the results will be store in an internal buffer.
configa pointer to a structure containing parameters which configure the behavior of the json generator.
allocFuncsan optional pointer to a structure which allows the client to overide the memory allocation used by yajl. May be NULL, in which case malloc/free/realloc will be used.
ctxa context pointer that will be passed to the printer callback.
Returns:
an allocated handle on success, NULL on failure (bad params)
YAJL_API yajl_gen_status yajl_gen_array_close ( yajl_gen  hand)
YAJL_API yajl_gen_status yajl_gen_array_open ( yajl_gen  hand)
YAJL_API yajl_gen_status yajl_gen_bool ( yajl_gen  hand,
int  boolean 
)
YAJL_API void yajl_gen_clear ( yajl_gen  hand)

clear yajl's output buffer, but maintain all internal generation state. This function will not "reset" the generator state, and is intended to enable incremental JSON outputing.

YAJL_API yajl_gen_status yajl_gen_double ( yajl_gen  hand,
double  number 
)

generate a floating point number. number may not be infinity or NaN, as these have no representation in JSON. In these cases the generator will return 'yajl_gen_invalid_number'

YAJL_API void yajl_gen_free ( yajl_gen  handle)

free a generator handle

YAJL_API yajl_gen_status yajl_gen_get_buf ( yajl_gen  hand,
const unsigned char **  buf,
unsigned int *  len 
)

access the null terminated generator buffer. If incrementally outputing JSON, one should call yajl_gen_clear to clear the buffer. This allows stream generation.

YAJL_API yajl_gen_status yajl_gen_integer ( yajl_gen  hand,
long int  number 
)
YAJL_API yajl_gen_status yajl_gen_map_close ( yajl_gen  hand)
YAJL_API yajl_gen_status yajl_gen_map_open ( yajl_gen  hand)
YAJL_API yajl_gen_status yajl_gen_null ( yajl_gen  hand)
YAJL_API yajl_gen_status yajl_gen_number ( yajl_gen  hand,
const char *  num,
unsigned int  len 
)
YAJL_API yajl_gen_status yajl_gen_string ( yajl_gen  hand,
const unsigned char *  str,
unsigned int  len 
)