Fork of my MQTTGateway

Dependencies:   mbed-http

Committer:
vpcola
Date:
Sat Apr 08 14:45:51 2017 +0000
Revision:
0:f1d3878b8dd9
Initial commit

Who changed what in which revision?

UserRevisionLine numberNew contents of line
vpcola 0:f1d3878b8dd9 1 #ifndef __JSMN_H_
vpcola 0:f1d3878b8dd9 2 #define __JSMN_H_
vpcola 0:f1d3878b8dd9 3
vpcola 0:f1d3878b8dd9 4 #include <stddef.h>
vpcola 0:f1d3878b8dd9 5
vpcola 0:f1d3878b8dd9 6 #ifdef __cplusplus
vpcola 0:f1d3878b8dd9 7 extern "C" {
vpcola 0:f1d3878b8dd9 8 #endif
vpcola 0:f1d3878b8dd9 9
vpcola 0:f1d3878b8dd9 10 /**
vpcola 0:f1d3878b8dd9 11 * JSON type identifier. Basic types are:
vpcola 0:f1d3878b8dd9 12 * o Object
vpcola 0:f1d3878b8dd9 13 * o Array
vpcola 0:f1d3878b8dd9 14 * o String
vpcola 0:f1d3878b8dd9 15 * o Other primitive: number, boolean (true/false) or null
vpcola 0:f1d3878b8dd9 16 */
vpcola 0:f1d3878b8dd9 17 typedef enum {
vpcola 0:f1d3878b8dd9 18 JSMN_UNDEFINED = 0,
vpcola 0:f1d3878b8dd9 19 JSMN_OBJECT = 1,
vpcola 0:f1d3878b8dd9 20 JSMN_ARRAY = 2,
vpcola 0:f1d3878b8dd9 21 JSMN_STRING = 3,
vpcola 0:f1d3878b8dd9 22 JSMN_PRIMITIVE = 4
vpcola 0:f1d3878b8dd9 23 } jsmntype_t;
vpcola 0:f1d3878b8dd9 24
vpcola 0:f1d3878b8dd9 25 enum jsmnerr {
vpcola 0:f1d3878b8dd9 26 /* Not enough tokens were provided */
vpcola 0:f1d3878b8dd9 27 JSMN_ERROR_NOMEM = -1,
vpcola 0:f1d3878b8dd9 28 /* Invalid character inside JSON string */
vpcola 0:f1d3878b8dd9 29 JSMN_ERROR_INVAL = -2,
vpcola 0:f1d3878b8dd9 30 /* The string is not a full JSON packet, more bytes expected */
vpcola 0:f1d3878b8dd9 31 JSMN_ERROR_PART = -3
vpcola 0:f1d3878b8dd9 32 };
vpcola 0:f1d3878b8dd9 33
vpcola 0:f1d3878b8dd9 34 /**
vpcola 0:f1d3878b8dd9 35 * JSON token description.
vpcola 0:f1d3878b8dd9 36 * type type (object, array, string etc.)
vpcola 0:f1d3878b8dd9 37 * start start position in JSON data string
vpcola 0:f1d3878b8dd9 38 * end end position in JSON data string
vpcola 0:f1d3878b8dd9 39 */
vpcola 0:f1d3878b8dd9 40 typedef struct {
vpcola 0:f1d3878b8dd9 41 jsmntype_t type;
vpcola 0:f1d3878b8dd9 42 int start;
vpcola 0:f1d3878b8dd9 43 int end;
vpcola 0:f1d3878b8dd9 44 int size;
vpcola 0:f1d3878b8dd9 45 #ifdef JSMN_PARENT_LINKS
vpcola 0:f1d3878b8dd9 46 int parent;
vpcola 0:f1d3878b8dd9 47 #endif
vpcola 0:f1d3878b8dd9 48 } jsmntok_t;
vpcola 0:f1d3878b8dd9 49
vpcola 0:f1d3878b8dd9 50 /**
vpcola 0:f1d3878b8dd9 51 * JSON parser. Contains an array of token blocks available. Also stores
vpcola 0:f1d3878b8dd9 52 * the string being parsed now and current position in that string
vpcola 0:f1d3878b8dd9 53 */
vpcola 0:f1d3878b8dd9 54 typedef struct {
vpcola 0:f1d3878b8dd9 55 unsigned int pos; /* offset in the JSON string */
vpcola 0:f1d3878b8dd9 56 unsigned int toknext; /* next token to allocate */
vpcola 0:f1d3878b8dd9 57 int toksuper; /* superior token node, e.g parent object or array */
vpcola 0:f1d3878b8dd9 58 } jsmn_parser;
vpcola 0:f1d3878b8dd9 59
vpcola 0:f1d3878b8dd9 60 /**
vpcola 0:f1d3878b8dd9 61 * Create JSON parser over an array of tokens
vpcola 0:f1d3878b8dd9 62 */
vpcola 0:f1d3878b8dd9 63 void jsmn_init(jsmn_parser *parser);
vpcola 0:f1d3878b8dd9 64
vpcola 0:f1d3878b8dd9 65 /**
vpcola 0:f1d3878b8dd9 66 * Run JSON parser. It parses a JSON data string into and array of tokens, each describing
vpcola 0:f1d3878b8dd9 67 * a single JSON object.
vpcola 0:f1d3878b8dd9 68 */
vpcola 0:f1d3878b8dd9 69 int jsmn_parse(jsmn_parser *parser, const char *js, size_t len,
vpcola 0:f1d3878b8dd9 70 jsmntok_t *tokens, unsigned int num_tokens);
vpcola 0:f1d3878b8dd9 71
vpcola 0:f1d3878b8dd9 72 #ifdef __cplusplus
vpcola 0:f1d3878b8dd9 73 }
vpcola 0:f1d3878b8dd9 74 #endif
vpcola 0:f1d3878b8dd9 75
vpcola 0:f1d3878b8dd9 76 #endif /* __JSMN_H_ */