Demo application for using the AT&T IoT Starter Kit Powered by AWS.

Dependencies:   SDFileSystem

Fork of ATT_AWS_IoT_demo by Anthony Phillips

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers jsmn.h Source File

jsmn.h

Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 2010 Serge A. Zaitsev
00003  *
00004  * Permission is hereby granted, free of charge, to any person obtaining a copy
00005  * of this software and associated documentation files (the "Software"), to deal
00006  * in the Software without restriction, including without limitation the rights
00007  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
00008  * copies of the Software, and to permit persons to whom the Software is
00009  * furnished to do so, subject to the following conditions:
00010  *
00011  * The above copyright notice and this permission notice shall be included in
00012  * all copies or substantial portions of the Software.
00013  *
00014  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
00015  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
00016  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
00017  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
00018  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
00019  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
00020  * THE SOFTWARE.
00021  */
00022 
00023 /**
00024  * @file jsmn.h
00025  * @brief Definition of the JSMN (Jasmine) JSON parser.
00026  *
00027  * For more information on JSMN:
00028  * @see http://zserge.com/jsmn.html
00029  */
00030 
00031 #ifndef __JSMN_H_
00032 #define __JSMN_H_
00033 #include <stddef.h>
00034 #define JSMN_STRICT
00035 #ifdef __cplusplus
00036 extern "C" {
00037 #endif
00038 
00039 /**
00040  * JSON type identifier. Basic types are:
00041  * o Object
00042  * o Array
00043  * o String
00044  * o Other primitive: number, boolean (true/false) or null
00045  */
00046 typedef enum {
00047     JSMN_PRIMITIVE = 0, JSMN_OBJECT = 1, JSMN_ARRAY = 2, JSMN_STRING = 3
00048 } jsmntype_t;
00049 
00050 typedef enum {
00051     /* Not enough tokens were provided */
00052     JSMN_ERROR_NOMEM = -1,
00053     /* Invalid character inside JSON string */
00054     JSMN_ERROR_INVAL = -2,
00055     /* The string is not a full JSON packet, more bytes expected */
00056     JSMN_ERROR_PART = -3,
00057 } jsmnerr_t;
00058 
00059 /**
00060  * JSON token description.
00061  * @param        type    type (object, array, string etc.)
00062  * @param        start   start position in JSON data string
00063  * @param        end     end position in JSON data string
00064  */
00065 typedef struct {
00066     jsmntype_t type;
00067     int start;
00068     int end;
00069     int size;
00070 #ifdef JSMN_PARENT_LINKS
00071     int parent;
00072 #endif
00073 } jsmntok_t;
00074 
00075 /**
00076  * JSON parser. Contains an array of token blocks available. Also stores
00077  * the string being parsed now and current position in that string
00078  */
00079 typedef struct {
00080     unsigned int pos; /* offset in the JSON string */
00081     unsigned int toknext; /* next token to allocate */
00082     int toksuper; /* superior token node, e.g parent object or array */
00083 } jsmn_parser;
00084 
00085 /**
00086  * Create JSON parser over an array of tokens
00087  */
00088 void jsmn_init(jsmn_parser *parser);
00089 
00090 /**
00091  * Run JSON parser. It parses a JSON data string into and array of tokens, each describing
00092  * a single JSON object.
00093  */
00094 jsmnerr_t jsmn_parse(jsmn_parser *parser, const char *js, size_t len,
00095         jsmntok_t *tokens, unsigned int num_tokens);
00096 
00097 #ifdef __cplusplus
00098 }
00099 #endif
00100 
00101 #endif /* __JSMN_H_ */
00102