WarpTwin
Documentation for WarpTwin models and classes.
Loading...
Searching...
No Matches
json.h
Go to the documentation of this file.
1/*
2 * MIT License
3 *
4 * Copyright (c) 2010 Serge Zaitsev
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to deal
8 * in the Software without restriction, including without limitation the rights
9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 * copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 * SOFTWARE.
23 */
24/*
25These utilities adapted from jsmn https://github.com/zserge/jsmn/blob/master/jsmn.h
26for ATTX.
27
28NOTE: Code coverage exception 9/1/2025:
29There are two logical branches in this set of code which are unreachable under normal conditions
30and the code cannot operate without (and therefore the branch cannot be excluded from coverage).
31Therefore this code receives an exception from 100% mc/dc code coverage, as to generate 100% code
32coverage would require modifying an external library, a more unsafe option than the exception.
33Dev: Alex Reynolds
34Tech Authority: Alex Reynolds
35Reviewer: Ryan Hughes
36*/
37#ifndef UTILS_JSON_H
38#define UTILS_JSON_H
39
40#include <stddef.h>
41
42#ifdef __cplusplus
43extern "C" {
44#endif
45
46#ifdef JSMN_STATIC
47#define JSMN_API static
48#else
49#define JSMN_API extern
50#endif
51
59typedef enum {
61 JSMN_OBJECT = 1 << 0,
62 JSMN_ARRAY = 1 << 1,
63 JSMN_STRING = 1 << 2,
66
67enum jsmnerr {
68 /* Not enough tokens were provided */
70 /* Invalid character inside JSON string */
72 /* The string is not a full JSON packet, more bytes expected */
74};
75
82typedef struct jsmntok {
84 int start;
85 int end;
86 int size;
87#ifdef JSMN_PARENT_LINKS
88 int parent;
89#endif
91
96typedef struct jsmn_parser {
97 unsigned int pos; /* offset in the JSON string */
98 unsigned int toknext; /* next token to allocate */
99 int toksuper; /* superior token node, e.g. parent object or array */
101
105JSMN_API void jsmn_init(jsmn_parser *parser);
106
112JSMN_API int jsmn_parse(jsmn_parser *parser, const char *js, const size_t len,
113 jsmntok_t *tokens, const unsigned int num_tokens);
114
115
116#ifdef __cplusplus
117}
118#endif
119
120#endif /* JSMN_H */
jsmntype_t
Definition json.h:59
@ JSMN_PRIMITIVE
Definition json.h:64
@ JSMN_OBJECT
Definition json.h:61
@ JSMN_UNDEFINED
Definition json.h:60
@ JSMN_ARRAY
Definition json.h:62
@ JSMN_STRING
Definition json.h:63
void jsmn_init(jsmn_parser *parser)
Definition json.cpp:393
struct jsmntok jsmntok_t
#define JSMN_API
Definition json.h:49
int jsmn_parse(jsmn_parser *parser, const char *js, const size_t len, jsmntok_t *tokens, const unsigned int num_tokens)
Definition json.cpp:202
jsmnerr
Definition json.h:67
@ JSMN_ERROR_INVAL
Definition json.h:71
@ JSMN_ERROR_PART
Definition json.h:73
@ JSMN_ERROR_NOMEM
Definition json.h:69
Definition json.h:96
unsigned int pos
Definition json.h:97
int toksuper
Definition json.h:99
unsigned int toknext
Definition json.h:98
Definition json.h:82
int end
Definition json.h:85
int size
Definition json.h:86
int start
Definition json.h:84
jsmntype_t type
Definition json.h:83