JSON parsing library by Andrii Mamchur https://github.com/amamchur/jsonlite

Dependents:   M2X_dev MTS_M2x_Example1 MTS_M2x_Example m2x-demo-all ... more

Committer:
citrusbyte
Date:
Thu Oct 24 12:20:56 2013 +0000
Revision:
0:01a2f8de46c8
Child:
1:807034181e02
Initial commit of jsonlite library

Who changed what in which revision?

UserRevisionLine numberNew contents of line
citrusbyte 0:01a2f8de46c8 1 //
citrusbyte 0:01a2f8de46c8 2 // Copyright 2012-2013, Andrii Mamchur
citrusbyte 0:01a2f8de46c8 3 //
citrusbyte 0:01a2f8de46c8 4 // Licensed under the Apache License, Version 2.0 (the "License");
citrusbyte 0:01a2f8de46c8 5 // you may not use this file except in compliance with the License.
citrusbyte 0:01a2f8de46c8 6 // You may obtain a copy of the License at
citrusbyte 0:01a2f8de46c8 7 //
citrusbyte 0:01a2f8de46c8 8 // http://www.apache.org/licenses/LICENSE-2.0
citrusbyte 0:01a2f8de46c8 9 //
citrusbyte 0:01a2f8de46c8 10 // Unless required by applicable law or agreed to in writing, software
citrusbyte 0:01a2f8de46c8 11 // distributed under the License is distributed on an "AS IS" BASIS,
citrusbyte 0:01a2f8de46c8 12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
citrusbyte 0:01a2f8de46c8 13 // See the License for the specific language governing permissions and
citrusbyte 0:01a2f8de46c8 14 // limitations under the License
citrusbyte 0:01a2f8de46c8 15
citrusbyte 0:01a2f8de46c8 16 #ifndef JSONLITE_H
citrusbyte 0:01a2f8de46c8 17 #define JSONLITE_H
citrusbyte 0:01a2f8de46c8 18
citrusbyte 0:01a2f8de46c8 19 // #include "jsonlite_parser.h"
citrusbyte 0:01a2f8de46c8 20 //
citrusbyte 0:01a2f8de46c8 21 // Copyright 2012-2013, Andrii Mamchur
citrusbyte 0:01a2f8de46c8 22 //
citrusbyte 0:01a2f8de46c8 23 // Licensed under the Apache License, Version 2.0 (the "License");
citrusbyte 0:01a2f8de46c8 24 // you may not use this file except in compliance with the License.
citrusbyte 0:01a2f8de46c8 25 // You may obtain a copy of the License at
citrusbyte 0:01a2f8de46c8 26 //
citrusbyte 0:01a2f8de46c8 27 // http://www.apache.org/licenses/LICENSE-2.0
citrusbyte 0:01a2f8de46c8 28 //
citrusbyte 0:01a2f8de46c8 29 // Unless required by applicable law or agreed to in writing, software
citrusbyte 0:01a2f8de46c8 30 // distributed under the License is distributed on an "AS IS" BASIS,
citrusbyte 0:01a2f8de46c8 31 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
citrusbyte 0:01a2f8de46c8 32 // See the License for the specific language governing permissions and
citrusbyte 0:01a2f8de46c8 33 // limitations under the License
citrusbyte 0:01a2f8de46c8 34
citrusbyte 0:01a2f8de46c8 35 #ifndef JSONLITE_PARSER_H
citrusbyte 0:01a2f8de46c8 36 #define JSONLITE_PARSER_H
citrusbyte 0:01a2f8de46c8 37
citrusbyte 0:01a2f8de46c8 38 #include <stdio.h>
citrusbyte 0:01a2f8de46c8 39 #include <stddef.h>
citrusbyte 0:01a2f8de46c8 40 #include <stdint.h>
citrusbyte 0:01a2f8de46c8 41 // #include "jsonlite_token.h"
citrusbyte 0:01a2f8de46c8 42 //
citrusbyte 0:01a2f8de46c8 43 // Copyright 2012-2013, Andrii Mamchur
citrusbyte 0:01a2f8de46c8 44 //
citrusbyte 0:01a2f8de46c8 45 // Licensed under the Apache License, Version 2.0 (the "License");
citrusbyte 0:01a2f8de46c8 46 // you may not use this file except in compliance with the License.
citrusbyte 0:01a2f8de46c8 47 // You may obtain a copy of the License at
citrusbyte 0:01a2f8de46c8 48 //
citrusbyte 0:01a2f8de46c8 49 // http://www.apache.org/licenses/LICENSE-2.0
citrusbyte 0:01a2f8de46c8 50 //
citrusbyte 0:01a2f8de46c8 51 // Unless required by applicable law or agreed to in writing, software
citrusbyte 0:01a2f8de46c8 52 // distributed under the License is distributed on an "AS IS" BASIS,
citrusbyte 0:01a2f8de46c8 53 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
citrusbyte 0:01a2f8de46c8 54 // See the License for the specific language governing permissions and
citrusbyte 0:01a2f8de46c8 55 // limitations under the License
citrusbyte 0:01a2f8de46c8 56
citrusbyte 0:01a2f8de46c8 57 #ifndef JSONLITE_TOKEN_H
citrusbyte 0:01a2f8de46c8 58 #define JSONLITE_TOKEN_H
citrusbyte 0:01a2f8de46c8 59
citrusbyte 0:01a2f8de46c8 60 #include <stdio.h>
citrusbyte 0:01a2f8de46c8 61 #include <stddef.h>
citrusbyte 0:01a2f8de46c8 62 #include <stdint.h>
citrusbyte 0:01a2f8de46c8 63
citrusbyte 0:01a2f8de46c8 64 #ifdef __cplusplus
citrusbyte 0:01a2f8de46c8 65 extern "C" {
citrusbyte 0:01a2f8de46c8 66 #endif
citrusbyte 0:01a2f8de46c8 67 struct jsonlite_token;
citrusbyte 0:01a2f8de46c8 68 struct jsonlite_parser_struct;
citrusbyte 0:01a2f8de46c8 69
citrusbyte 0:01a2f8de46c8 70 /** @brief Provides the hints for number token parsing.
citrusbyte 0:01a2f8de46c8 71 *
citrusbyte 0:01a2f8de46c8 72 * This values is valid for jsonlite_parser_callbacks::number_found callback only.
citrusbyte 0:01a2f8de46c8 73 */
citrusbyte 0:01a2f8de46c8 74 typedef enum {
citrusbyte 0:01a2f8de46c8 75 /** @brief Indicates that number token has integer part.
citrusbyte 0:01a2f8de46c8 76 *
citrusbyte 0:01a2f8de46c8 77 * @note
citrusbyte 0:01a2f8de46c8 78 * This flag is always set because of JSON number always has integer part (value .123 is not allowed).
citrusbyte 0:01a2f8de46c8 79 */
citrusbyte 0:01a2f8de46c8 80 jsonlite_number_int = 0x01,
citrusbyte 0:01a2f8de46c8 81
citrusbyte 0:01a2f8de46c8 82 /** @brief Indicates that number token has fraction part.
citrusbyte 0:01a2f8de46c8 83 *
citrusbyte 0:01a2f8de46c8 84 * This flag will set if token has an fraction part. For example: 123.987;
citrusbyte 0:01a2f8de46c8 85 * in current case fraction part is .987.
citrusbyte 0:01a2f8de46c8 86 */
citrusbyte 0:01a2f8de46c8 87 jsonlite_number_frac = 0x02,
citrusbyte 0:01a2f8de46c8 88
citrusbyte 0:01a2f8de46c8 89 /** @brief Indicates that number token has exponent part.
citrusbyte 0:01a2f8de46c8 90 *
citrusbyte 0:01a2f8de46c8 91 * This flag will set if token has an exponent part.
citrusbyte 0:01a2f8de46c8 92 *
citrusbyte 0:01a2f8de46c8 93 * For example:
citrusbyte 0:01a2f8de46c8 94 * For integer values: 123e5, 123E5, 123E+5, 123e+5;
citrusbyte 0:01a2f8de46c8 95 * all of this numbers are equal to each other and has exponent part.
citrusbyte 0:01a2f8de46c8 96 *
citrusbyte 0:01a2f8de46c8 97 * An other case 12300000 is also equals to previous numbers but has no exponent part.
citrusbyte 0:01a2f8de46c8 98 *
citrusbyte 0:01a2f8de46c8 99 * For floating point values: 123.01e5, 123.01E5, 123.01E+5, 123.01e+5;
citrusbyte 0:01a2f8de46c8 100 * all of this number are equal to each other and has exponent part.
citrusbyte 0:01a2f8de46c8 101 * An other case 12301000 is also equals to previous numbers but has no exponent part.
citrusbyte 0:01a2f8de46c8 102 */
citrusbyte 0:01a2f8de46c8 103 jsonlite_number_exp = 0x04,
citrusbyte 0:01a2f8de46c8 104
citrusbyte 0:01a2f8de46c8 105 /** @brief Indicates that number token has negative value.
citrusbyte 0:01a2f8de46c8 106 *
citrusbyte 0:01a2f8de46c8 107 * This flag will set if token starts with '-' character.
citrusbyte 0:01a2f8de46c8 108 */
citrusbyte 0:01a2f8de46c8 109 jsonlite_number_negative = 0x08,
citrusbyte 0:01a2f8de46c8 110
citrusbyte 0:01a2f8de46c8 111 /** @brief Indicates that number token starts with zero character.
citrusbyte 0:01a2f8de46c8 112 */
citrusbyte 0:01a2f8de46c8 113 jsonlite_number_zero_leading = 0x10,
citrusbyte 0:01a2f8de46c8 114 \
citrusbyte 0:01a2f8de46c8 115 /** @brief Indicates that number token starts with digit that is greater 0.
citrusbyte 0:01a2f8de46c8 116 */
citrusbyte 0:01a2f8de46c8 117 jsonlite_number_digit_leading = 0x20
citrusbyte 0:01a2f8de46c8 118 } jsonlite_number_type;
citrusbyte 0:01a2f8de46c8 119
citrusbyte 0:01a2f8de46c8 120 /** @brief Provides the hints for string token parsing.
citrusbyte 0:01a2f8de46c8 121 *
citrusbyte 0:01a2f8de46c8 122 * This values is valid for jsonlite_parser_callbacks::string_found
citrusbyte 0:01a2f8de46c8 123 * and jsonlite_parser_callbacks::key_found callbacks only.
citrusbyte 0:01a2f8de46c8 124 */
citrusbyte 0:01a2f8de46c8 125 typedef enum {
citrusbyte 0:01a2f8de46c8 126 /** @brief Indicates that string token contains ASCII characters.
citrusbyte 0:01a2f8de46c8 127 *
citrusbyte 0:01a2f8de46c8 128 * @note
citrusbyte 0:01a2f8de46c8 129 * This flag is always set because of JSON string always has ASCII characters.
citrusbyte 0:01a2f8de46c8 130 */
citrusbyte 0:01a2f8de46c8 131 jsonlite_string_ascii = 0x01,
citrusbyte 0:01a2f8de46c8 132
citrusbyte 0:01a2f8de46c8 133 /** @brief Indicates that string token has the sequences of UTF-8 characters.
citrusbyte 0:01a2f8de46c8 134 *
citrusbyte 0:01a2f8de46c8 135 * @note
citrusbyte 0:01a2f8de46c8 136 * This flag will set if string token has 2, 3 or 4 subsequently.
citrusbyte 0:01a2f8de46c8 137 */
citrusbyte 0:01a2f8de46c8 138 jsonlite_string_utf8 = 0x02,
citrusbyte 0:01a2f8de46c8 139
citrusbyte 0:01a2f8de46c8 140 /** @brief Indicates that string token has an escaped character(s).
citrusbyte 0:01a2f8de46c8 141 *
citrusbyte 0:01a2f8de46c8 142 * This flag will be set if string token has one or more following escaped character:
citrusbyte 0:01a2f8de46c8 143 * - \\"
citrusbyte 0:01a2f8de46c8 144 * - \\\\
citrusbyte 0:01a2f8de46c8 145 * - \\n
citrusbyte 0:01a2f8de46c8 146 * - \\r
citrusbyte 0:01a2f8de46c8 147 * - \\/
citrusbyte 0:01a2f8de46c8 148 * - \\b
citrusbyte 0:01a2f8de46c8 149 * - \\f
citrusbyte 0:01a2f8de46c8 150 * - \\t
citrusbyte 0:01a2f8de46c8 151 */
citrusbyte 0:01a2f8de46c8 152 jsonlite_string_escape = 0x04,
citrusbyte 0:01a2f8de46c8 153
citrusbyte 0:01a2f8de46c8 154 /** @brief Indicates that string token has one or more unicode escaped character(s).
citrusbyte 0:01a2f8de46c8 155 *
citrusbyte 0:01a2f8de46c8 156 * This flag will be set if string token has \\uXXXX escape - where (XXXX is an unicode character code)
citrusbyte 0:01a2f8de46c8 157 */
citrusbyte 0:01a2f8de46c8 158 jsonlite_string_unicode_escape = 0x04
citrusbyte 0:01a2f8de46c8 159 } jsonlite_string_type;
citrusbyte 0:01a2f8de46c8 160
citrusbyte 0:01a2f8de46c8 161 /** @brief Contains information about parsed token.
citrusbyte 0:01a2f8de46c8 162 */
citrusbyte 0:01a2f8de46c8 163 typedef struct jsonlite_token {
citrusbyte 0:01a2f8de46c8 164 /** @brief This variable is reserved for high-level libraries.
citrusbyte 0:01a2f8de46c8 165 */
citrusbyte 0:01a2f8de46c8 166 void *ext;
citrusbyte 0:01a2f8de46c8 167
citrusbyte 0:01a2f8de46c8 168 /** @brief Contains the start position of token.
citrusbyte 0:01a2f8de46c8 169 */
citrusbyte 0:01a2f8de46c8 170 const uint8_t *start;
citrusbyte 0:01a2f8de46c8 171
citrusbyte 0:01a2f8de46c8 172 /** @brief Contains the end position of tokens.
citrusbyte 0:01a2f8de46c8 173 *
citrusbyte 0:01a2f8de46c8 174 * End position does not below to token, it should be interpreted as position of zero character.
citrusbyte 0:01a2f8de46c8 175 * @note
citrusbyte 0:01a2f8de46c8 176 * To measure token length you can use following expression: token->end - token->start.
citrusbyte 0:01a2f8de46c8 177 */
citrusbyte 0:01a2f8de46c8 178 const uint8_t *end;
citrusbyte 0:01a2f8de46c8 179
citrusbyte 0:01a2f8de46c8 180 /** @brief Contains the hints for token parsing.
citrusbyte 0:01a2f8de46c8 181 */
citrusbyte 0:01a2f8de46c8 182 union {
citrusbyte 0:01a2f8de46c8 183 /** @brief Contains the hints for number token parsing.
citrusbyte 0:01a2f8de46c8 184 */
citrusbyte 0:01a2f8de46c8 185 jsonlite_number_type number_type;
citrusbyte 0:01a2f8de46c8 186
citrusbyte 0:01a2f8de46c8 187 /** @brief Contains the hints for string token parsing.
citrusbyte 0:01a2f8de46c8 188 */
citrusbyte 0:01a2f8de46c8 189 jsonlite_string_type string_type;
citrusbyte 0:01a2f8de46c8 190 };
citrusbyte 0:01a2f8de46c8 191 } jsonlite_token;
citrusbyte 0:01a2f8de46c8 192
citrusbyte 0:01a2f8de46c8 193
citrusbyte 0:01a2f8de46c8 194 /** @brief Returns a size of memory that is required for token conversion to UTF-8 string.
citrusbyte 0:01a2f8de46c8 195 * @param ts jsonlite token
citrusbyte 0:01a2f8de46c8 196 * @return 0 if ts is NULL; otherwise required size of for token conversion.
citrusbyte 0:01a2f8de46c8 197 */
citrusbyte 0:01a2f8de46c8 198 size_t jsonlite_token_decode_size_for_uft8(jsonlite_token *ts);
citrusbyte 0:01a2f8de46c8 199
citrusbyte 0:01a2f8de46c8 200 /** @brief Converts specified token to UTF-8 string.
citrusbyte 0:01a2f8de46c8 201 *
citrusbyte 0:01a2f8de46c8 202 * Function converts specified token to UTF-8 string encoding and copy zero terminated string to buffer.
citrusbyte 0:01a2f8de46c8 203 * @note
citrusbyte 0:01a2f8de46c8 204 * Function will alloc memory by itself if *buffer == NULL.
citrusbyte 0:01a2f8de46c8 205 * In this case you are responsible for memory releasing by using free() function.
citrusbyte 0:01a2f8de46c8 206 * @param ts jsonlite token
citrusbyte 0:01a2f8de46c8 207 * @return length in bytes of converted string.
citrusbyte 0:01a2f8de46c8 208 */
citrusbyte 0:01a2f8de46c8 209 size_t jsonlite_token_decode_to_uft8(jsonlite_token *ts, uint8_t **buffer);
citrusbyte 0:01a2f8de46c8 210
citrusbyte 0:01a2f8de46c8 211 /** @brief Returns a size of memory that is required for token conversion to UTF-16 string.
citrusbyte 0:01a2f8de46c8 212 * @param ts jsonlite token
citrusbyte 0:01a2f8de46c8 213 * @return 0 if ts is NULL; otherwise required size of for token conversion.
citrusbyte 0:01a2f8de46c8 214 */
citrusbyte 0:01a2f8de46c8 215 size_t jsonlite_token_decode_size_for_uft16(jsonlite_token *ts);
citrusbyte 0:01a2f8de46c8 216
citrusbyte 0:01a2f8de46c8 217 /** @brief Converts specified token to UTF-16 string.
citrusbyte 0:01a2f8de46c8 218 *
citrusbyte 0:01a2f8de46c8 219 * Function converts specified token to UTF-16 string encoding and copy zero terminated string to buffer.
citrusbyte 0:01a2f8de46c8 220 * @note
citrusbyte 0:01a2f8de46c8 221 * Function will alloc memory by itself if *buffer == NULL.
citrusbyte 0:01a2f8de46c8 222 * In this case you are responsible for memory releasing by using free() function.
citrusbyte 0:01a2f8de46c8 223 * @param ts jsonlite token
citrusbyte 0:01a2f8de46c8 224 * @return length in bytes of converted string.
citrusbyte 0:01a2f8de46c8 225 */
citrusbyte 0:01a2f8de46c8 226 size_t jsonlite_token_decode_to_uft16(jsonlite_token *ts, uint16_t **buffer);
citrusbyte 0:01a2f8de46c8 227
citrusbyte 0:01a2f8de46c8 228 /** @brief Converts hex digit to integer value.
citrusbyte 0:01a2f8de46c8 229 *
citrusbyte 0:01a2f8de46c8 230 * @param c a ASCII character.
citrusbyte 0:01a2f8de46c8 231 * @return integer value of hex character,
citrusbyte 0:01a2f8de46c8 232 * if character belongs to set [0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F,a,b,c,d,e,f]; otherwise 0xFF.
citrusbyte 0:01a2f8de46c8 233 */
citrusbyte 0:01a2f8de46c8 234 uint8_t jsonlite_hex_char_to_uint8(uint8_t c);
citrusbyte 0:01a2f8de46c8 235
citrusbyte 0:01a2f8de46c8 236 #ifdef __cplusplus
citrusbyte 0:01a2f8de46c8 237 }
citrusbyte 0:01a2f8de46c8 238 #endif
citrusbyte 0:01a2f8de46c8 239
citrusbyte 0:01a2f8de46c8 240 #endif
citrusbyte 0:01a2f8de46c8 241
citrusbyte 0:01a2f8de46c8 242 // #include "jsonlite_types.h"
citrusbyte 0:01a2f8de46c8 243 //
citrusbyte 0:01a2f8de46c8 244 // Copyright 2012-2013, Andrii Mamchur
citrusbyte 0:01a2f8de46c8 245 //
citrusbyte 0:01a2f8de46c8 246 // Licensed under the Apache License, Version 2.0 (the "License");
citrusbyte 0:01a2f8de46c8 247 // you may not use this file except in compliance with the License.
citrusbyte 0:01a2f8de46c8 248 // You may obtain a copy of the License at
citrusbyte 0:01a2f8de46c8 249 //
citrusbyte 0:01a2f8de46c8 250 // http://www.apache.org/licenses/LICENSE-2.0
citrusbyte 0:01a2f8de46c8 251 //
citrusbyte 0:01a2f8de46c8 252 // Unless required by applicable law or agreed to in writing, software
citrusbyte 0:01a2f8de46c8 253 // distributed under the License is distributed on an "AS IS" BASIS,
citrusbyte 0:01a2f8de46c8 254 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
citrusbyte 0:01a2f8de46c8 255 // See the License for the specific language governing permissions and
citrusbyte 0:01a2f8de46c8 256 // limitations under the License
citrusbyte 0:01a2f8de46c8 257
citrusbyte 0:01a2f8de46c8 258 #ifndef JSONLITE_TYPES_H
citrusbyte 0:01a2f8de46c8 259 #define JSONLITE_TYPES_H
citrusbyte 0:01a2f8de46c8 260
citrusbyte 0:01a2f8de46c8 261 typedef enum {
citrusbyte 0:01a2f8de46c8 262 jsonlite_result_unknown = -1,
citrusbyte 0:01a2f8de46c8 263 jsonlite_result_ok,
citrusbyte 0:01a2f8de46c8 264 jsonlite_result_end_of_stream,
citrusbyte 0:01a2f8de46c8 265 jsonlite_result_depth_limit,
citrusbyte 0:01a2f8de46c8 266 jsonlite_result_invalid_argument,
citrusbyte 0:01a2f8de46c8 267 jsonlite_result_expected_object_or_array,
citrusbyte 0:01a2f8de46c8 268 jsonlite_result_expected_value,
citrusbyte 0:01a2f8de46c8 269 jsonlite_result_expected_key_or_end,
citrusbyte 0:01a2f8de46c8 270 jsonlite_result_expected_key,
citrusbyte 0:01a2f8de46c8 271 jsonlite_result_expected_colon,
citrusbyte 0:01a2f8de46c8 272 jsonlite_result_expected_comma_or_end,
citrusbyte 0:01a2f8de46c8 273 jsonlite_result_invalid_escape,
citrusbyte 0:01a2f8de46c8 274 jsonlite_result_invalid_number,
citrusbyte 0:01a2f8de46c8 275 jsonlite_result_invalid_token,
citrusbyte 0:01a2f8de46c8 276 jsonlite_result_invalid_utf8,
citrusbyte 0:01a2f8de46c8 277 jsonlite_result_suspended,
citrusbyte 0:01a2f8de46c8 278
citrusbyte 0:01a2f8de46c8 279 jsonlite_result_not_allowed
citrusbyte 0:01a2f8de46c8 280 } jsonlite_result;
citrusbyte 0:01a2f8de46c8 281
citrusbyte 0:01a2f8de46c8 282
citrusbyte 0:01a2f8de46c8 283 #endif
citrusbyte 0:01a2f8de46c8 284
citrusbyte 0:01a2f8de46c8 285
citrusbyte 0:01a2f8de46c8 286 #ifdef __cplusplus
citrusbyte 0:01a2f8de46c8 287 extern "C" {
citrusbyte 0:01a2f8de46c8 288 #endif
citrusbyte 0:01a2f8de46c8 289
citrusbyte 0:01a2f8de46c8 290 struct jsonlite_parser_struct;
citrusbyte 0:01a2f8de46c8 291 typedef struct jsonlite_parser_struct* jsonlite_parser;
citrusbyte 0:01a2f8de46c8 292
citrusbyte 0:01a2f8de46c8 293 /** @brief Contains callback information.
citrusbyte 0:01a2f8de46c8 294 */
citrusbyte 0:01a2f8de46c8 295 typedef struct {
citrusbyte 0:01a2f8de46c8 296 /** @brief jsonlite parser object that initiate callback.
citrusbyte 0:01a2f8de46c8 297 * @note
citrusbyte 0:01a2f8de46c8 298 * You can use ::jsonlite_parser_suspend to stop tokenization.
citrusbyte 0:01a2f8de46c8 299 */
citrusbyte 0:01a2f8de46c8 300 jsonlite_parser parser;
citrusbyte 0:01a2f8de46c8 301
citrusbyte 0:01a2f8de46c8 302 /** @brief Reserved for client usage.
citrusbyte 0:01a2f8de46c8 303 */
citrusbyte 0:01a2f8de46c8 304 void *client_state;
citrusbyte 0:01a2f8de46c8 305 } jsonlite_callback_context;
citrusbyte 0:01a2f8de46c8 306
citrusbyte 0:01a2f8de46c8 307 /** @brief Type of value callback function.
citrusbyte 0:01a2f8de46c8 308 */
citrusbyte 0:01a2f8de46c8 309 typedef void (*jsonlite_value_callback)(jsonlite_callback_context *, jsonlite_token *);
citrusbyte 0:01a2f8de46c8 310
citrusbyte 0:01a2f8de46c8 311 /** @brief Type of state callback function.
citrusbyte 0:01a2f8de46c8 312 */
citrusbyte 0:01a2f8de46c8 313 typedef void (*jsonlite_state_callback)(jsonlite_callback_context *);
citrusbyte 0:01a2f8de46c8 314
citrusbyte 0:01a2f8de46c8 315 /** @brief Contains references to client callback functions.
citrusbyte 0:01a2f8de46c8 316 *
citrusbyte 0:01a2f8de46c8 317 * You can use the global jsonlite_default_callbacks constant to initialize default values.
citrusbyte 0:01a2f8de46c8 318 */
citrusbyte 0:01a2f8de46c8 319 typedef struct {
citrusbyte 0:01a2f8de46c8 320 /** @brief Called when parser finished tokenization.
citrusbyte 0:01a2f8de46c8 321 * You can retrieve result of parsing using jsonlite_parser_get_result.
citrusbyte 0:01a2f8de46c8 322 */
citrusbyte 0:01a2f8de46c8 323 jsonlite_state_callback parse_finished;
citrusbyte 0:01a2f8de46c8 324
citrusbyte 0:01a2f8de46c8 325 /** @brief Called when parser found object start.
citrusbyte 0:01a2f8de46c8 326 */
citrusbyte 0:01a2f8de46c8 327 jsonlite_state_callback object_start;
citrusbyte 0:01a2f8de46c8 328
citrusbyte 0:01a2f8de46c8 329 /** @brief Called when parser found object end.
citrusbyte 0:01a2f8de46c8 330 */
citrusbyte 0:01a2f8de46c8 331 jsonlite_state_callback object_end;
citrusbyte 0:01a2f8de46c8 332
citrusbyte 0:01a2f8de46c8 333 /** @brief Called when parser found array start.
citrusbyte 0:01a2f8de46c8 334 */
citrusbyte 0:01a2f8de46c8 335 jsonlite_state_callback array_start;
citrusbyte 0:01a2f8de46c8 336
citrusbyte 0:01a2f8de46c8 337 /** @brief Called when parser found array end.
citrusbyte 0:01a2f8de46c8 338 */
citrusbyte 0:01a2f8de46c8 339 jsonlite_state_callback array_end;
citrusbyte 0:01a2f8de46c8 340
citrusbyte 0:01a2f8de46c8 341 /** @brief Called when parser found \a true token.
citrusbyte 0:01a2f8de46c8 342 */
citrusbyte 0:01a2f8de46c8 343 jsonlite_state_callback true_found;
citrusbyte 0:01a2f8de46c8 344
citrusbyte 0:01a2f8de46c8 345 /** @brief Called when parser found \a false token.
citrusbyte 0:01a2f8de46c8 346 */
citrusbyte 0:01a2f8de46c8 347 jsonlite_state_callback false_found;
citrusbyte 0:01a2f8de46c8 348
citrusbyte 0:01a2f8de46c8 349 /** @brief Called when parser found \a null token.
citrusbyte 0:01a2f8de46c8 350 */
citrusbyte 0:01a2f8de46c8 351 jsonlite_state_callback null_found;
citrusbyte 0:01a2f8de46c8 352
citrusbyte 0:01a2f8de46c8 353 /** @brief Called when parser found key token.
citrusbyte 0:01a2f8de46c8 354 */
citrusbyte 0:01a2f8de46c8 355 jsonlite_value_callback key_found;
citrusbyte 0:01a2f8de46c8 356
citrusbyte 0:01a2f8de46c8 357 /** @brief Called when parser found string token.
citrusbyte 0:01a2f8de46c8 358 */
citrusbyte 0:01a2f8de46c8 359 jsonlite_value_callback string_found;
citrusbyte 0:01a2f8de46c8 360
citrusbyte 0:01a2f8de46c8 361 /** @brief Called when parser found number token.
citrusbyte 0:01a2f8de46c8 362 */
citrusbyte 0:01a2f8de46c8 363 jsonlite_value_callback number_found;
citrusbyte 0:01a2f8de46c8 364
citrusbyte 0:01a2f8de46c8 365 /** @brief Callbacks' context, will be past as first parameter of callback function.
citrusbyte 0:01a2f8de46c8 366 */
citrusbyte 0:01a2f8de46c8 367 jsonlite_callback_context context;
citrusbyte 0:01a2f8de46c8 368 } jsonlite_parser_callbacks;
citrusbyte 0:01a2f8de46c8 369
citrusbyte 0:01a2f8de46c8 370 /** @brief Estimates memory usage.
citrusbyte 0:01a2f8de46c8 371 * @note
citrusbyte 0:01a2f8de46c8 372 * This value depends on CPU architectures.
citrusbyte 0:01a2f8de46c8 373 * @param depth the parsing depth.
citrusbyte 0:01a2f8de46c8 374 * @return Estimated size in bytes.
citrusbyte 0:01a2f8de46c8 375 */
citrusbyte 0:01a2f8de46c8 376 size_t jsonlite_parser_estimate_size(size_t depth);
citrusbyte 0:01a2f8de46c8 377
citrusbyte 0:01a2f8de46c8 378 /** @brief Creates and initializes new instance of parser object.
citrusbyte 0:01a2f8de46c8 379 *
citrusbyte 0:01a2f8de46c8 380 * You should release jsonlite_parser object using ::jsonlite_parser_release.
citrusbyte 0:01a2f8de46c8 381 * @see jsonlite_parser
citrusbyte 0:01a2f8de46c8 382 * @see jsonlite_parser_release
citrusbyte 0:01a2f8de46c8 383 * @param depth the parsing depth.
citrusbyte 0:01a2f8de46c8 384 * @return jsonlite_parser object.
citrusbyte 0:01a2f8de46c8 385 */
citrusbyte 0:01a2f8de46c8 386 jsonlite_parser jsonlite_parser_init(size_t depth);
citrusbyte 0:01a2f8de46c8 387
citrusbyte 0:01a2f8de46c8 388 /** \brief Copies provided callbacks structure to parser object.
citrusbyte 0:01a2f8de46c8 389 * @see jsonlite_parser
citrusbyte 0:01a2f8de46c8 390 * @see jsonlite_parser_callbacks
citrusbyte 0:01a2f8de46c8 391 * @see jsonlite_result
citrusbyte 0:01a2f8de46c8 392 * @param parser the parser object.
citrusbyte 0:01a2f8de46c8 393 * @param parser the callbacks object.
citrusbyte 0:01a2f8de46c8 394 * @return jsonlite_result_invalid_argument when parser or cbs are NULL; otherwise jsonlite_result_ok.
citrusbyte 0:01a2f8de46c8 395 */
citrusbyte 0:01a2f8de46c8 396 jsonlite_result jsonlite_parser_set_callback(jsonlite_parser parser, const jsonlite_parser_callbacks *cbs);
citrusbyte 0:01a2f8de46c8 397
citrusbyte 0:01a2f8de46c8 398 /** \brief Returns result of last operation.
citrusbyte 0:01a2f8de46c8 399 * @see jsonlite_parser
citrusbyte 0:01a2f8de46c8 400 * @see jsonlite_result
citrusbyte 0:01a2f8de46c8 401 * @param parser the parser object.
citrusbyte 0:01a2f8de46c8 402 * @return jsonlite_result_invalid_argument when parser is NULL; otherwise s result of last operation.
citrusbyte 0:01a2f8de46c8 403 */
citrusbyte 0:01a2f8de46c8 404 jsonlite_result jsonlite_parser_get_result(jsonlite_parser parser);
citrusbyte 0:01a2f8de46c8 405
citrusbyte 0:01a2f8de46c8 406 /** \brief Performs JSON tokenization.
citrusbyte 0:01a2f8de46c8 407 *
citrusbyte 0:01a2f8de46c8 408 * jsonlite is a chunk parser and you can use this function to parser a fragment of JSON.
citrusbyte 0:01a2f8de46c8 409 * @see jsonlite_parser
citrusbyte 0:01a2f8de46c8 410 * @see jsonlite_result
citrusbyte 0:01a2f8de46c8 411 * @param parser the parser object.
citrusbyte 0:01a2f8de46c8 412 * @param buffer the pointer to JSON payload buffer.
citrusbyte 0:01a2f8de46c8 413 * @param size the JSON payload buffer size.
citrusbyte 0:01a2f8de46c8 414 * @return JSON parsing result or jsonlite_result_invalid_argument when some parameter is invalid.
citrusbyte 0:01a2f8de46c8 415 *
citrusbyte 0:01a2f8de46c8 416 * There is an example of JSON validation
citrusbyte 0:01a2f8de46c8 417 * @code{.c}
citrusbyte 0:01a2f8de46c8 418 * char json[] = "{\"key\" : 12345, \"obj\": {}, \"array\":[null, true, false, \"string\"]}";
citrusbyte 0:01a2f8de46c8 419 * jsonlite_parser p = jsonlite_parser_init(16);
citrusbyte 0:01a2f8de46c8 420 * jsonlite_result result = jsonlite_parser_tokenize(p, json, sizeof(json));
citrusbyte 0:01a2f8de46c8 421 * assert(result == jsonlite_result_ok);
citrusbyte 0:01a2f8de46c8 422 * jsonlite_parser_release(p);
citrusbyte 0:01a2f8de46c8 423 * @endcode
citrusbyte 0:01a2f8de46c8 424 *
citrusbyte 0:01a2f8de46c8 425 * There is an another example of JSON chunk parsing.
citrusbyte 0:01a2f8de46c8 426 * @code{.c}
citrusbyte 0:01a2f8de46c8 427 * char chunk1[] = "{\"key\" : 12345, \"obj\": {}, \"arr";
citrusbyte 0:01a2f8de46c8 428 * char chunk2[] = "ay\":[null, true, false, \"string\"]}";
citrusbyte 0:01a2f8de46c8 429 * jsonlite_parser p = jsonlite_parser_init(16);
citrusbyte 0:01a2f8de46c8 430 *
citrusbyte 0:01a2f8de46c8 431 * jsonlite_result result = jsonlite_parser_tokenize(p, chunk1, sizeof(chunk1) - 1);
citrusbyte 0:01a2f8de46c8 432 * assert(result == jsonlite_result_end_of_stream);
citrusbyte 0:01a2f8de46c8 433 * // Now you can release or reuse chunk1 buffer.
citrusbyte 0:01a2f8de46c8 434 *
citrusbyte 0:01a2f8de46c8 435 * result = jsonlite_parser_tokenize(p, chunk2, sizeof(chunk2) - 1);
citrusbyte 0:01a2f8de46c8 436 * assert(result == jsonlite_result_ok);
citrusbyte 0:01a2f8de46c8 437 *
citrusbyte 0:01a2f8de46c8 438 * jsonlite_parser_release(p);
citrusbyte 0:01a2f8de46c8 439 * @endcode
citrusbyte 0:01a2f8de46c8 440 */
citrusbyte 0:01a2f8de46c8 441 jsonlite_result jsonlite_parser_tokenize(jsonlite_parser parser, const void *buffer, size_t size);
citrusbyte 0:01a2f8de46c8 442
citrusbyte 0:01a2f8de46c8 443 /** \brief Resumes JSON tokenization.
citrusbyte 0:01a2f8de46c8 444 * @see jsonlite_parser
citrusbyte 0:01a2f8de46c8 445 * @see jsonlite_result
citrusbyte 0:01a2f8de46c8 446 * @param parser the parser object.
citrusbyte 0:01a2f8de46c8 447 * @return JSON parsing result or jsonlite_result_invalid_argument when parser is NULL.
citrusbyte 0:01a2f8de46c8 448 */
citrusbyte 0:01a2f8de46c8 449 jsonlite_result jsonlite_parser_resume(jsonlite_parser parser);
citrusbyte 0:01a2f8de46c8 450
citrusbyte 0:01a2f8de46c8 451 /** \brief Suspends JSON tokenization.
citrusbyte 0:01a2f8de46c8 452 *
citrusbyte 0:01a2f8de46c8 453 * You can continue tokenization later by calling ::jsonlite_parser_resume.
citrusbyte 0:01a2f8de46c8 454 * @see jsonlite_parser
citrusbyte 0:01a2f8de46c8 455 * @see jsonlite_result
citrusbyte 0:01a2f8de46c8 456 * @param parser the parser object.
citrusbyte 0:01a2f8de46c8 457 * @return jsonlite_result_invalid_argument when parser is NULL;
citrusbyte 0:01a2f8de46c8 458 * jsonlite_result_not_allowed when operation is not allowed;
citrusbyte 0:01a2f8de46c8 459 * otherwise jsonlite_result_ok.
citrusbyte 0:01a2f8de46c8 460 */
citrusbyte 0:01a2f8de46c8 461 jsonlite_result jsonlite_parser_suspend(jsonlite_parser parser);
citrusbyte 0:01a2f8de46c8 462
citrusbyte 0:01a2f8de46c8 463 /** \brief Releases parser object.
citrusbyte 0:01a2f8de46c8 464 *
citrusbyte 0:01a2f8de46c8 465 * If parser is NULL, jsonlite_parser_release does nothing.
citrusbyte 0:01a2f8de46c8 466 * @see jsonlite_parser
citrusbyte 0:01a2f8de46c8 467 * @see jsonlite_result
citrusbyte 0:01a2f8de46c8 468 * @param parser the parser object.
citrusbyte 0:01a2f8de46c8 469 */
citrusbyte 0:01a2f8de46c8 470 void jsonlite_parser_release(jsonlite_parser parser);
citrusbyte 0:01a2f8de46c8 471
citrusbyte 0:01a2f8de46c8 472 /** \brief jsonlite_parser_callbacks structure initialized with callbacks that do nothing.
citrusbyte 0:01a2f8de46c8 473 */
citrusbyte 0:01a2f8de46c8 474 extern const jsonlite_parser_callbacks jsonlite_default_callbacks;
citrusbyte 0:01a2f8de46c8 475
citrusbyte 0:01a2f8de46c8 476 #ifdef __cplusplus
citrusbyte 0:01a2f8de46c8 477 }
citrusbyte 0:01a2f8de46c8 478 #endif
citrusbyte 0:01a2f8de46c8 479
citrusbyte 0:01a2f8de46c8 480 #endif
citrusbyte 0:01a2f8de46c8 481
citrusbyte 0:01a2f8de46c8 482 // #include "jsonlite_builder.h"
citrusbyte 0:01a2f8de46c8 483 //
citrusbyte 0:01a2f8de46c8 484 // Copyright 2012-2013, Andrii Mamchur
citrusbyte 0:01a2f8de46c8 485 //
citrusbyte 0:01a2f8de46c8 486 // Licensed under the Apache License, Version 2.0 (the "License");
citrusbyte 0:01a2f8de46c8 487 // you may not use this file except in compliance with the License.
citrusbyte 0:01a2f8de46c8 488 // You may obtain a copy of the License at
citrusbyte 0:01a2f8de46c8 489 //
citrusbyte 0:01a2f8de46c8 490 // http://www.apache.org/licenses/LICENSE-2.0
citrusbyte 0:01a2f8de46c8 491 //
citrusbyte 0:01a2f8de46c8 492 // Unless required by applicable law or agreed to in writing, software
citrusbyte 0:01a2f8de46c8 493 // distributed under the License is distributed on an "AS IS" BASIS,
citrusbyte 0:01a2f8de46c8 494 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
citrusbyte 0:01a2f8de46c8 495 // See the License for the specific language governing permissions and
citrusbyte 0:01a2f8de46c8 496 // limitations under the License
citrusbyte 0:01a2f8de46c8 497
citrusbyte 0:01a2f8de46c8 498 #ifndef JSONLITE_BUILDER_H
citrusbyte 0:01a2f8de46c8 499 #define JSONLITE_BUILDER_H
citrusbyte 0:01a2f8de46c8 500
citrusbyte 0:01a2f8de46c8 501 #include <stdio.h>
citrusbyte 0:01a2f8de46c8 502 // #include "jsonlite_types.h"
citrusbyte 0:01a2f8de46c8 503
citrusbyte 0:01a2f8de46c8 504
citrusbyte 0:01a2f8de46c8 505 #ifdef __cplusplus
citrusbyte 0:01a2f8de46c8 506 extern "C" {
citrusbyte 0:01a2f8de46c8 507 #endif
citrusbyte 0:01a2f8de46c8 508
citrusbyte 0:01a2f8de46c8 509 struct jsonlite_builder_struct;
citrusbyte 0:01a2f8de46c8 510 typedef struct jsonlite_builder_struct* jsonlite_builder;
citrusbyte 0:01a2f8de46c8 511
citrusbyte 0:01a2f8de46c8 512 /** @brief Creates and initializes new instance of builder object.
citrusbyte 0:01a2f8de46c8 513 *
citrusbyte 0:01a2f8de46c8 514 * You should release jsonlite_builder object using ::jsonlite_builder_release.
citrusbyte 0:01a2f8de46c8 515 * @see jsonlite_builder
citrusbyte 0:01a2f8de46c8 516 * @see jsonlite_builder_release
citrusbyte 0:01a2f8de46c8 517 * @param depth the builder depth
citrusbyte 0:01a2f8de46c8 518 * @return jsonlite_builder object
citrusbyte 0:01a2f8de46c8 519 */
citrusbyte 0:01a2f8de46c8 520 jsonlite_builder jsonlite_builder_init(size_t depth);
citrusbyte 0:01a2f8de46c8 521
citrusbyte 0:01a2f8de46c8 522 /** \brief Releases builder object.
citrusbyte 0:01a2f8de46c8 523 *
citrusbyte 0:01a2f8de46c8 524 * If builder is NULL, jsonlite_builder_release does nothing.
citrusbyte 0:01a2f8de46c8 525 * @see jsonlite_builder
citrusbyte 0:01a2f8de46c8 526 * @see jsonlite_result
citrusbyte 0:01a2f8de46c8 527 * @param builder the builder object
citrusbyte 0:01a2f8de46c8 528 * @return jsonlite_result_invalid_argument when builder is NULL; otherwise jsonlite_result_ok.
citrusbyte 0:01a2f8de46c8 529 */
citrusbyte 0:01a2f8de46c8 530 jsonlite_result jsonlite_builder_release(jsonlite_builder builder);
citrusbyte 0:01a2f8de46c8 531
citrusbyte 0:01a2f8de46c8 532 /** \brief Sets beautify indentation. Default is 0.
citrusbyte 0:01a2f8de46c8 533 *
citrusbyte 0:01a2f8de46c8 534 * @see jsonlite_builder
citrusbyte 0:01a2f8de46c8 535 * @see jsonlite_result
citrusbyte 0:01a2f8de46c8 536 * @param builder the builder object
citrusbyte 0:01a2f8de46c8 537 * @param indentation the beautify indentation; 0 - disabled
citrusbyte 0:01a2f8de46c8 538 * @return jsonlite_result_invalid_argument when builder is NULL; otherwise jsonlite_result_ok.
citrusbyte 0:01a2f8de46c8 539 */
citrusbyte 0:01a2f8de46c8 540 jsonlite_result jsonlite_builder_set_indentation(jsonlite_builder builder, size_t indentation);
citrusbyte 0:01a2f8de46c8 541
citrusbyte 0:01a2f8de46c8 542 /** \brief Sets format for double values. Default is "%.16g".
citrusbyte 0:01a2f8de46c8 543 *
citrusbyte 0:01a2f8de46c8 544 * jsonlite_builder_set_double_format copies format parameter and you can safety release it.
citrusbyte 0:01a2f8de46c8 545 * @see jsonlite_builder
citrusbyte 0:01a2f8de46c8 546 * @see jsonlite_result
citrusbyte 0:01a2f8de46c8 547 * @param builder the builder object
citrusbyte 0:01a2f8de46c8 548 * @param format the double format; see sprintf function for details
citrusbyte 0:01a2f8de46c8 549 * @return jsonlite_result_invalid_argument when builder or format are NULL; otherwise jsonlite_result_ok.
citrusbyte 0:01a2f8de46c8 550 */
citrusbyte 0:01a2f8de46c8 551 jsonlite_result jsonlite_builder_set_double_format(jsonlite_builder builder, const char *format);
citrusbyte 0:01a2f8de46c8 552
citrusbyte 0:01a2f8de46c8 553 /** \brief Begin JSON object.
citrusbyte 0:01a2f8de46c8 554 *
citrusbyte 0:01a2f8de46c8 555 * @see jsonlite_builder
citrusbyte 0:01a2f8de46c8 556 * @see jsonlite_result
citrusbyte 0:01a2f8de46c8 557 * @param builder the builder object
citrusbyte 0:01a2f8de46c8 558 * @return jsonlite_result_invalid_argument when builder is NULL;
citrusbyte 0:01a2f8de46c8 559 * jsonlite_result_not_allowed when operation is not allowed;
citrusbyte 0:01a2f8de46c8 560 * otherwise jsonlite_result_ok.
citrusbyte 0:01a2f8de46c8 561 */
citrusbyte 0:01a2f8de46c8 562 jsonlite_result jsonlite_builder_object_begin(jsonlite_builder builder);
citrusbyte 0:01a2f8de46c8 563
citrusbyte 0:01a2f8de46c8 564 /** \brief End JSON object.
citrusbyte 0:01a2f8de46c8 565 *
citrusbyte 0:01a2f8de46c8 566 * @see jsonlite_builder
citrusbyte 0:01a2f8de46c8 567 * @see jsonlite_result
citrusbyte 0:01a2f8de46c8 568 * @param builder the builder object
citrusbyte 0:01a2f8de46c8 569 * @return jsonlite_result_invalid_argument when builder is NULL;
citrusbyte 0:01a2f8de46c8 570 * jsonlite_result_not_allowed when operation is not allowed;
citrusbyte 0:01a2f8de46c8 571 * otherwise jsonlite_result_ok.
citrusbyte 0:01a2f8de46c8 572 */
citrusbyte 0:01a2f8de46c8 573 jsonlite_result jsonlite_builder_object_end(jsonlite_builder builder);
citrusbyte 0:01a2f8de46c8 574
citrusbyte 0:01a2f8de46c8 575 /** \brief Begin JSON array.
citrusbyte 0:01a2f8de46c8 576 *
citrusbyte 0:01a2f8de46c8 577 * @see jsonlite_builder
citrusbyte 0:01a2f8de46c8 578 * @see jsonlite_result
citrusbyte 0:01a2f8de46c8 579 * @param builder the builder object
citrusbyte 0:01a2f8de46c8 580 * @return jsonlite_result_invalid_argument when builder is NULL;
citrusbyte 0:01a2f8de46c8 581 * jsonlite_result_not_allowed when operation is not allowed;
citrusbyte 0:01a2f8de46c8 582 * otherwise jsonlite_result_ok.
citrusbyte 0:01a2f8de46c8 583 */
citrusbyte 0:01a2f8de46c8 584 jsonlite_result jsonlite_builder_array_begin(jsonlite_builder builder);
citrusbyte 0:01a2f8de46c8 585
citrusbyte 0:01a2f8de46c8 586 /** \brief End JSON array.
citrusbyte 0:01a2f8de46c8 587 *
citrusbyte 0:01a2f8de46c8 588 * @see jsonlite_builder
citrusbyte 0:01a2f8de46c8 589 * @see jsonlite_result
citrusbyte 0:01a2f8de46c8 590 * @param builder the builder object
citrusbyte 0:01a2f8de46c8 591 * @return jsonlite_result_invalid_argument when builder is NULL;
citrusbyte 0:01a2f8de46c8 592 * jsonlite_result_not_allowed when operation is not allowed;
citrusbyte 0:01a2f8de46c8 593 * otherwise jsonlite_result_ok.
citrusbyte 0:01a2f8de46c8 594 */
citrusbyte 0:01a2f8de46c8 595 jsonlite_result jsonlite_builder_array_end(jsonlite_builder builder);
citrusbyte 0:01a2f8de46c8 596
citrusbyte 0:01a2f8de46c8 597 /** \brief Write JSON key.
citrusbyte 0:01a2f8de46c8 598 *
citrusbyte 0:01a2f8de46c8 599 * jsonlite_builder_key performs two-character sequence escape for
citrusbyte 0:01a2f8de46c8 600 * U+0022, U+005C, U+002F, U+0008, U+000C, U+000A, U+000D and U+0009
citrusbyte 0:01a2f8de46c8 601 * @see jsonlite_builder
citrusbyte 0:01a2f8de46c8 602 * @see jsonlite_result
citrusbyte 0:01a2f8de46c8 603 * @param builder the builder object
citrusbyte 0:01a2f8de46c8 604 * @param data the UTF-8 encoded string
citrusbyte 0:01a2f8de46c8 605 * @param length the string length
citrusbyte 0:01a2f8de46c8 606 * @return jsonlite_result_invalid_argument when builder or data are NULL;
citrusbyte 0:01a2f8de46c8 607 * jsonlite_result_not_allowed when operation is not allowed;
citrusbyte 0:01a2f8de46c8 608 * otherwise jsonlite_result_ok.
citrusbyte 0:01a2f8de46c8 609 */
citrusbyte 0:01a2f8de46c8 610 jsonlite_result jsonlite_builder_key(jsonlite_builder builder, const char *data, size_t length);
citrusbyte 0:01a2f8de46c8 611
citrusbyte 0:01a2f8de46c8 612 /** \brief Write string value.
citrusbyte 0:01a2f8de46c8 613 *
citrusbyte 0:01a2f8de46c8 614 * jsonlite_builder_key performs two-character sequence escape for
citrusbyte 0:01a2f8de46c8 615 * U+0022, U+005C, U+002F, U+0008, U+000C, U+000A, U+000D and U+0009
citrusbyte 0:01a2f8de46c8 616 * @see jsonlite_builder
citrusbyte 0:01a2f8de46c8 617 * @see jsonlite_result
citrusbyte 0:01a2f8de46c8 618 * @param builder the builder object
citrusbyte 0:01a2f8de46c8 619 * @param data the UTF-8 encoded string
citrusbyte 0:01a2f8de46c8 620 * @param length the string length
citrusbyte 0:01a2f8de46c8 621 * @return jsonlite_result_invalid_argument when builder or data are NULL;
citrusbyte 0:01a2f8de46c8 622 * jsonlite_result_not_allowed when operation is not allowed;
citrusbyte 0:01a2f8de46c8 623 * otherwise jsonlite_result_ok.
citrusbyte 0:01a2f8de46c8 624 */
citrusbyte 0:01a2f8de46c8 625 jsonlite_result jsonlite_builder_string(jsonlite_builder builder, const char *data, size_t length);
citrusbyte 0:01a2f8de46c8 626
citrusbyte 0:01a2f8de46c8 627 /** \brief Write integer value.
citrusbyte 0:01a2f8de46c8 628 *
citrusbyte 0:01a2f8de46c8 629 * @see jsonlite_builder
citrusbyte 0:01a2f8de46c8 630 * @see jsonlite_result
citrusbyte 0:01a2f8de46c8 631 * @param builder the builder object
citrusbyte 0:01a2f8de46c8 632 * @param value the integer value
citrusbyte 0:01a2f8de46c8 633 * @return jsonlite_result_invalid_argument when builder is NULL;
citrusbyte 0:01a2f8de46c8 634 * jsonlite_result_not_allowed when operation is not allowed;
citrusbyte 0:01a2f8de46c8 635 * otherwise jsonlite_result_ok.
citrusbyte 0:01a2f8de46c8 636 */
citrusbyte 0:01a2f8de46c8 637 jsonlite_result jsonlite_builder_int(jsonlite_builder builder, long long value);
citrusbyte 0:01a2f8de46c8 638
citrusbyte 0:01a2f8de46c8 639 /** \brief Write double value.
citrusbyte 0:01a2f8de46c8 640 *
citrusbyte 0:01a2f8de46c8 641 * @see jsonlite_builder
citrusbyte 0:01a2f8de46c8 642 * @see jsonlite_result
citrusbyte 0:01a2f8de46c8 643 * @param builder the builder object
citrusbyte 0:01a2f8de46c8 644 * @param value the double value
citrusbyte 0:01a2f8de46c8 645 * @return jsonlite_result_invalid_argument when builder is NULL;
citrusbyte 0:01a2f8de46c8 646 * jsonlite_result_not_allowed when operation is not allowed;
citrusbyte 0:01a2f8de46c8 647 * otherwise jsonlite_result_ok.
citrusbyte 0:01a2f8de46c8 648 */
citrusbyte 0:01a2f8de46c8 649 jsonlite_result jsonlite_builder_double(jsonlite_builder builder, double value);
citrusbyte 0:01a2f8de46c8 650
citrusbyte 0:01a2f8de46c8 651 /** \brief Write true value.
citrusbyte 0:01a2f8de46c8 652 *
citrusbyte 0:01a2f8de46c8 653 * @see jsonlite_builder
citrusbyte 0:01a2f8de46c8 654 * @see jsonlite_result
citrusbyte 0:01a2f8de46c8 655 * @param builder the builder object
citrusbyte 0:01a2f8de46c8 656 * @return jsonlite_result_invalid_argument when builder is NULL;
citrusbyte 0:01a2f8de46c8 657 * jsonlite_result_not_allowed when operation is not allowed;
citrusbyte 0:01a2f8de46c8 658 * otherwise jsonlite_result_ok.
citrusbyte 0:01a2f8de46c8 659 */
citrusbyte 0:01a2f8de46c8 660 jsonlite_result jsonlite_builder_true(jsonlite_builder builder);
citrusbyte 0:01a2f8de46c8 661
citrusbyte 0:01a2f8de46c8 662 /** \brief Write false value.
citrusbyte 0:01a2f8de46c8 663 *
citrusbyte 0:01a2f8de46c8 664 * @see jsonlite_builder
citrusbyte 0:01a2f8de46c8 665 * @see jsonlite_result
citrusbyte 0:01a2f8de46c8 666 * @param builder the builder object
citrusbyte 0:01a2f8de46c8 667 * @return jsonlite_result_invalid_argument when builder is NULL;
citrusbyte 0:01a2f8de46c8 668 * jsonlite_result_not_allowed when operation is not allowed;
citrusbyte 0:01a2f8de46c8 669 * otherwise jsonlite_result_ok.
citrusbyte 0:01a2f8de46c8 670 */
citrusbyte 0:01a2f8de46c8 671 jsonlite_result jsonlite_builder_false(jsonlite_builder builder);
citrusbyte 0:01a2f8de46c8 672
citrusbyte 0:01a2f8de46c8 673 /** \brief Write null value.
citrusbyte 0:01a2f8de46c8 674 *
citrusbyte 0:01a2f8de46c8 675 * @see jsonlite_builder
citrusbyte 0:01a2f8de46c8 676 * @see jsonlite_result
citrusbyte 0:01a2f8de46c8 677 * @param builder the builder object
citrusbyte 0:01a2f8de46c8 678 * @return jsonlite_result_invalid_argument when builder is NULL;
citrusbyte 0:01a2f8de46c8 679 * jsonlite_result_not_allowed when operation is not allowed;
citrusbyte 0:01a2f8de46c8 680 * otherwise jsonlite_result_ok.
citrusbyte 0:01a2f8de46c8 681 */
citrusbyte 0:01a2f8de46c8 682 jsonlite_result jsonlite_builder_null(jsonlite_builder builder);
citrusbyte 0:01a2f8de46c8 683
citrusbyte 0:01a2f8de46c8 684 /** \brief Write raw key.
citrusbyte 0:01a2f8de46c8 685 *
citrusbyte 0:01a2f8de46c8 686 * jsonlite_builder_raw_key does not perform any transformation.
citrusbyte 0:01a2f8de46c8 687 * jsonlite_builder_raw_key wraps raw key with '"' (U+0022).
citrusbyte 0:01a2f8de46c8 688 * If data already was wrapped with '"' use following practice jsonlite_builder_raw_key(d, data + 1, size - 2);
citrusbyte 0:01a2f8de46c8 689 * @see jsonlite_builder
citrusbyte 0:01a2f8de46c8 690 * @see jsonlite_result
citrusbyte 0:01a2f8de46c8 691 * @param builder the builder object
citrusbyte 0:01a2f8de46c8 692 * @param data the raw data
citrusbyte 0:01a2f8de46c8 693 * @param length the data length
citrusbyte 0:01a2f8de46c8 694 * @return jsonlite_result_invalid_argument when builder or data are NULL;
citrusbyte 0:01a2f8de46c8 695 * jsonlite_result_not_allowed when operation is not allowed;
citrusbyte 0:01a2f8de46c8 696 * otherwise jsonlite_result_ok.
citrusbyte 0:01a2f8de46c8 697 */
citrusbyte 0:01a2f8de46c8 698 jsonlite_result jsonlite_builder_raw_key(jsonlite_builder builder, const void *data, size_t length);
citrusbyte 0:01a2f8de46c8 699
citrusbyte 0:01a2f8de46c8 700 /** \brief Write raw string.
citrusbyte 0:01a2f8de46c8 701 *
citrusbyte 0:01a2f8de46c8 702 * jsonlite_builder_raw_string does not perform any transformation.
citrusbyte 0:01a2f8de46c8 703 * jsonlite_builder_raw_string wraps raw string with '"' (U+0022).
citrusbyte 0:01a2f8de46c8 704 * If data already was wrapped with '"' use following practice jsonlite_builder_raw_string(d, data + 1, size - 2);
citrusbyte 0:01a2f8de46c8 705 * @see jsonlite_builder
citrusbyte 0:01a2f8de46c8 706 * @see jsonlite_result
citrusbyte 0:01a2f8de46c8 707 * @param builder the builder object
citrusbyte 0:01a2f8de46c8 708 * @param data the raw data
citrusbyte 0:01a2f8de46c8 709 * @param length the data length
citrusbyte 0:01a2f8de46c8 710 * @return jsonlite_result_invalid_argument when builder or data are NULL;
citrusbyte 0:01a2f8de46c8 711 * jsonlite_result_not_allowed when operation is not allowed;
citrusbyte 0:01a2f8de46c8 712 * otherwise jsonlite_result_ok.
citrusbyte 0:01a2f8de46c8 713 */
citrusbyte 0:01a2f8de46c8 714 jsonlite_result jsonlite_builder_raw_string(jsonlite_builder builder, const void *data, size_t length);
citrusbyte 0:01a2f8de46c8 715
citrusbyte 0:01a2f8de46c8 716 /** \brief Write raw value.
citrusbyte 0:01a2f8de46c8 717 *
citrusbyte 0:01a2f8de46c8 718 * jsonlite_builder_raw_value does not perform any transformation.
citrusbyte 0:01a2f8de46c8 719 * jsonlite_builder_raw_value does not wrap raw value with '"' (U+0022).
citrusbyte 0:01a2f8de46c8 720 * @see jsonlite_builder
citrusbyte 0:01a2f8de46c8 721 * @see jsonlite_result
citrusbyte 0:01a2f8de46c8 722 * @param builder the builder object
citrusbyte 0:01a2f8de46c8 723 * @param data the raw data
citrusbyte 0:01a2f8de46c8 724 * @param length the data length
citrusbyte 0:01a2f8de46c8 725 * @return jsonlite_result_invalid_argument when builder or data are NULL;
citrusbyte 0:01a2f8de46c8 726 * jsonlite_result_not_allowed when operation is not allowed;
citrusbyte 0:01a2f8de46c8 727 * otherwise jsonlite_result_ok.
citrusbyte 0:01a2f8de46c8 728 */
citrusbyte 0:01a2f8de46c8 729 jsonlite_result jsonlite_builder_raw_value(jsonlite_builder builder, const void *data, size_t length);
citrusbyte 0:01a2f8de46c8 730
citrusbyte 0:01a2f8de46c8 731 /** \brief Gets buffer data.
citrusbyte 0:01a2f8de46c8 732 *
citrusbyte 0:01a2f8de46c8 733 * You are responsible to free buffer using free function.
citrusbyte 0:01a2f8de46c8 734 * @see jsonlite_builder
citrusbyte 0:01a2f8de46c8 735 * @see jsonlite_result
citrusbyte 0:01a2f8de46c8 736 * @param builder the builder object
citrusbyte 0:01a2f8de46c8 737 * @param[out] buffer the output buffer
citrusbyte 0:01a2f8de46c8 738 * @param[out] size the buffer size
citrusbyte 0:01a2f8de46c8 739 * @return jsonlite_result_invalid_argument when builder, buffer or size are NULL;
citrusbyte 0:01a2f8de46c8 740 * jsonlite_result_not_allowed when operation is not allowed;
citrusbyte 0:01a2f8de46c8 741 * otherwise jsonlite_result_ok.
citrusbyte 0:01a2f8de46c8 742 */
citrusbyte 0:01a2f8de46c8 743 jsonlite_result jsonlite_builder_data(jsonlite_builder builder, char **buffer, size_t *size);
citrusbyte 0:01a2f8de46c8 744
citrusbyte 0:01a2f8de46c8 745 #ifdef __cplusplus
citrusbyte 0:01a2f8de46c8 746 }
citrusbyte 0:01a2f8de46c8 747 #endif
citrusbyte 0:01a2f8de46c8 748
citrusbyte 0:01a2f8de46c8 749 #endif
citrusbyte 0:01a2f8de46c8 750
citrusbyte 0:01a2f8de46c8 751 // #include "jsonlite_token_pool.h"
citrusbyte 0:01a2f8de46c8 752 //
citrusbyte 0:01a2f8de46c8 753 // Copyright 2012-2013, Andrii Mamchur
citrusbyte 0:01a2f8de46c8 754 //
citrusbyte 0:01a2f8de46c8 755 // Licensed under the Apache License, Version 2.0 (the "License");
citrusbyte 0:01a2f8de46c8 756 // you may not use this file except in compliance with the License.
citrusbyte 0:01a2f8de46c8 757 // You may obtain a copy of the License at
citrusbyte 0:01a2f8de46c8 758 //
citrusbyte 0:01a2f8de46c8 759 // http://www.apache.org/licenses/LICENSE-2.0
citrusbyte 0:01a2f8de46c8 760 //
citrusbyte 0:01a2f8de46c8 761 // Unless required by applicable law or agreed to in writing, software
citrusbyte 0:01a2f8de46c8 762 // distributed under the License is distributed on an "AS IS" BASIS,
citrusbyte 0:01a2f8de46c8 763 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
citrusbyte 0:01a2f8de46c8 764 // See the License for the specific language governing permissions and
citrusbyte 0:01a2f8de46c8 765 // limitations under the License
citrusbyte 0:01a2f8de46c8 766
citrusbyte 0:01a2f8de46c8 767 #ifndef JSONLITE_TOKEN_POOL_H
citrusbyte 0:01a2f8de46c8 768 #define JSONLITE_TOKEN_POOL_H
citrusbyte 0:01a2f8de46c8 769
citrusbyte 0:01a2f8de46c8 770 // #include "jsonlite_token.h"
citrusbyte 0:01a2f8de46c8 771
citrusbyte 0:01a2f8de46c8 772
citrusbyte 0:01a2f8de46c8 773 #ifdef __cplusplus
citrusbyte 0:01a2f8de46c8 774 extern "C" {
citrusbyte 0:01a2f8de46c8 775 #endif
citrusbyte 0:01a2f8de46c8 776
citrusbyte 0:01a2f8de46c8 777 typedef void (*jsonlite_token_pool_release_value_fn)(void *);
citrusbyte 0:01a2f8de46c8 778 typedef struct content_pool_size* jsonlite_token_pool;
citrusbyte 0:01a2f8de46c8 779
citrusbyte 0:01a2f8de46c8 780 typedef struct jsonlite_token_bucket {
citrusbyte 0:01a2f8de46c8 781 ptrdiff_t hash;
citrusbyte 0:01a2f8de46c8 782 const uint8_t *start;
citrusbyte 0:01a2f8de46c8 783 const uint8_t *end;
citrusbyte 0:01a2f8de46c8 784 const void *value;
citrusbyte 0:01a2f8de46c8 785 ptrdiff_t value_hash;
citrusbyte 0:01a2f8de46c8 786 } jsonlite_token_bucket;
citrusbyte 0:01a2f8de46c8 787
citrusbyte 0:01a2f8de46c8 788 jsonlite_token_pool jsonlite_token_pool_create(jsonlite_token_pool_release_value_fn release_fn);
citrusbyte 0:01a2f8de46c8 789 void jsonlite_token_pool_copy_tokens(jsonlite_token_pool pool);
citrusbyte 0:01a2f8de46c8 790 void jsonlite_token_pool_release(jsonlite_token_pool pool);
citrusbyte 0:01a2f8de46c8 791 jsonlite_token_bucket* jsonlite_token_pool_get_bucket(jsonlite_token_pool pool, jsonlite_token *token);
citrusbyte 0:01a2f8de46c8 792
citrusbyte 0:01a2f8de46c8 793 #ifdef __cplusplus
citrusbyte 0:01a2f8de46c8 794 }
citrusbyte 0:01a2f8de46c8 795 #endif
citrusbyte 0:01a2f8de46c8 796
citrusbyte 0:01a2f8de46c8 797 #endif
citrusbyte 0:01a2f8de46c8 798
citrusbyte 0:01a2f8de46c8 799
citrusbyte 0:01a2f8de46c8 800 #endif
citrusbyte 0:01a2f8de46c8 801
citrusbyte 0:01a2f8de46c8 802 /** @mainpage jsonlite Index Page
citrusbyte 0:01a2f8de46c8 803 *
citrusbyte 0:01a2f8de46c8 804 * @section intro_sec Introduction
citrusbyte 0:01a2f8de46c8 805 *
citrusbyte 0:01a2f8de46c8 806 * This is the introduction.
citrusbyte 0:01a2f8de46c8 807 *
citrusbyte 0:01a2f8de46c8 808 * @section install_sec Installation
citrusbyte 0:01a2f8de46c8 809 *
citrusbyte 0:01a2f8de46c8 810 * @subsection step1 Step 1: Opening the box
citrusbyte 0:01a2f8de46c8 811 *
citrusbyte 0:01a2f8de46c8 812 * etc...
citrusbyte 0:01a2f8de46c8 813 */
citrusbyte 0:01a2f8de46c8 814