dcerpc-nt: add UNION_ALIGN_TO... helpers
[wireshark-sm.git] / wsutil / jsmn.h
blob228c416013b15b27e30f32d729053fcab7f2570d
1 /** @file
3 Copyright (c) 2010 Serge A. Zaitsev
5 Permission is hereby granted, free of charge, to any person obtaining a copy
6 of this software and associated documentation files (the "Software"), to deal
7 in the Software without restriction, including without limitation the rights
8 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 copies of the Software, and to permit persons to whom the Software is
10 furnished to do so, subject to the following conditions:
12 The above copyright notice and this permission notice shall be included in
13 all copies or substantial portions of the Software.
15 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21 THE SOFTWARE.
24 #ifndef __JSMN_H_
25 #define __JSMN_H_
27 #include <stddef.h>
29 #ifdef __cplusplus
30 extern "C" {
31 #endif
33 /**
34 * JSON type identifier. Basic types are:
35 * o Object
36 * o Array
37 * o String
38 * o Other primitive: number, boolean (true/false) or null
40 typedef enum {
41 JSMN_UNDEFINED = 0,
42 JSMN_OBJECT = 1,
43 JSMN_ARRAY = 2,
44 JSMN_STRING = 3,
45 JSMN_PRIMITIVE = 4
46 } jsmntype_t;
48 enum jsmnerr {
49 /* Not enough tokens were provided */
50 JSMN_ERROR_NOMEM = -1,
51 /* Invalid character inside JSON string */
52 JSMN_ERROR_INVAL = -2,
53 /* The string is not a full JSON packet, more bytes expected */
54 JSMN_ERROR_PART = -3
57 /**
58 * JSON token description.
59 * type type (object, array, string etc.)
60 * start start position in JSON data string
61 * end end position in JSON data string
63 typedef struct {
64 jsmntype_t type;
65 int start;
66 int end;
67 int size;
68 #ifdef JSMN_PARENT_LINKS
69 int parent;
70 #endif
71 } jsmntok_t;
73 /**
74 * JSON parser. Contains an array of token blocks available. Also stores
75 * the string being parsed now and current position in that string
77 typedef struct {
78 unsigned int pos; /* offset in the JSON string */
79 unsigned int toknext; /* next token to allocate */
80 int toksuper; /* superior token node, e.g parent object or array */
81 } jsmn_parser;
83 /**
84 * Create JSON parser over an array of tokens
86 void jsmn_init(jsmn_parser *parser);
88 /**
89 * Run JSON parser. It parses a JSON data string into and array of tokens, each describing
90 * a single JSON object.
92 int jsmn_parse(jsmn_parser *parser, const char *js, size_t len,
93 jsmntok_t *tokens, unsigned int num_tokens);
95 #ifdef __cplusplus
97 #endif
99 #endif /* __JSMN_H_ */