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