]> Dogcows Code - chaz/yoink/blob - src/Moof/yajl/src/api/yajl_gen.h
55a836228cb5402032ab224969101e895f291065
[chaz/yoink] / src / Moof / yajl / src / api / yajl_gen.h
1 /*
2 * Copyright 2007-2009, Lloyd Hilaiel.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
6 * met:
7 *
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 *
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in
13 * the documentation and/or other materials provided with the
14 * distribution.
15 *
16 * 3. Neither the name of Lloyd Hilaiel nor the names of its
17 * contributors may be used to endorse or promote products derived
18 * from this software without specific prior written permission.
19 *
20 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
21 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
22 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
23 * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
24 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
25 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
26 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
28 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
29 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30 * POSSIBILITY OF SUCH DAMAGE.
31 */
32
33 /**
34 * \file yajl_gen.h
35 * Interface to YAJL's JSON generation facilities.
36 */
37
38 #include <yajl/yajl_common.h>
39
40 #ifndef __YAJL_GEN_H__
41 #define __YAJL_GEN_H__
42
43 #ifdef __cplusplus
44 extern "C" {
45 #endif
46 /** generator status codes */
47 typedef enum {
48 /** no error */
49 yajl_gen_status_ok = 0,
50 /** at a point where a map key is generated, a function other than
51 * yajl_gen_string was called */
52 yajl_gen_keys_must_be_strings,
53 /** YAJL's maximum generation depth was exceeded. see
54 * YAJL_MAX_DEPTH */
55 yajl_max_depth_exceeded,
56 /** A generator function (yajl_gen_XXX) was called while in an error
57 * state */
58 yajl_gen_in_error_state,
59 /** A complete JSON document has been generated */
60 yajl_gen_generation_complete
61 } yajl_gen_status;
62
63 /** an opaque handle to a generator */
64 typedef struct yajl_gen_t * yajl_gen;
65
66 /** configuration structure for the generator */
67 typedef struct {
68 /** generate indented (beautiful) output */
69 unsigned int beautify;
70 /** an opportunity to define an indent string. such as \\t or
71 * some number of spaces. default is four spaces ' '. This
72 * member is only relevant when beautify is true */
73 const char * indentString;
74 } yajl_gen_config;
75
76 /** allocate a generator handle
77 * \param config a pointer to a structure containing parameters which
78 * configure the behavior of the json generator
79 * \param allocFuncs an optional pointer to a structure which allows
80 * the client to overide the memory allocation
81 * used by yajl. May be NULL, in which case
82 * malloc/free/realloc will be used.
83 *
84 * \returns an allocated handle on success, NULL on failure (bad params)
85 */
86 yajl_gen YAJL_API yajl_gen_alloc(const yajl_gen_config * config,
87 const yajl_alloc_funcs * allocFuncs);
88
89 /** free a generator handle */
90 void YAJL_API yajl_gen_free(yajl_gen handle);
91
92 yajl_gen_status YAJL_API yajl_gen_integer(yajl_gen hand, long int number);
93 yajl_gen_status YAJL_API yajl_gen_double(yajl_gen hand, double number);
94 yajl_gen_status YAJL_API yajl_gen_number(yajl_gen hand,
95 const char * num,
96 unsigned int len);
97 yajl_gen_status YAJL_API yajl_gen_string(yajl_gen hand,
98 const unsigned char * str,
99 unsigned int len);
100 yajl_gen_status YAJL_API yajl_gen_null(yajl_gen hand);
101 yajl_gen_status YAJL_API yajl_gen_bool(yajl_gen hand, int boolean);
102 yajl_gen_status YAJL_API yajl_gen_map_open(yajl_gen hand);
103 yajl_gen_status YAJL_API yajl_gen_map_close(yajl_gen hand);
104 yajl_gen_status YAJL_API yajl_gen_array_open(yajl_gen hand);
105 yajl_gen_status YAJL_API yajl_gen_array_close(yajl_gen hand);
106
107 /** access the null terminated generator buffer. If incrementally
108 * outputing JSON, one should call yajl_gen_clear to clear the
109 * buffer. This allows stream generation. */
110 yajl_gen_status YAJL_API yajl_gen_get_buf(yajl_gen hand,
111 const unsigned char ** buf,
112 unsigned int * len);
113
114 /** clear yajl's output buffer, but maintain all internal generation
115 * state. This function will not "reset" the generator state, and is
116 * intended to enable incremental JSON outputing. */
117 void YAJL_API yajl_gen_clear(yajl_gen hand);
118
119 #ifdef __cplusplus
120 }
121 #endif
122
123 #endif
This page took 0.03178 seconds and 3 git commands to generate.