mirror of
				https://github.com/eledio-devices/thirdparty-ArduinoJson.git
				synced 2025-10-31 08:42:39 +01:00 
			
		
		
		
	Moved all JsonParser code in a sub-folder.
This commit is contained in:
		
				
					committed by
					
						 Benoît Blanchon
						Benoît Blanchon
					
				
			
			
				
	
			
			
			
						parent
						
							80e0a51c15
						
					
				
				
					commit
					3d8b31b1ec
				
			
							
								
								
									
										11
									
								
								JsonParser.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										11
									
								
								JsonParser.cpp
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,11 @@ | ||||
| /* | ||||
| * malloc-free JSON parser for Arduino | ||||
| * Benoit Blanchon 2014 - MIT License | ||||
| */ | ||||
|  | ||||
| // This file is here to help the Arduino IDE find the .cpp files | ||||
|  | ||||
| #include "JsonParser/JsonArray.cpp" | ||||
| #include "JsonParser/JsonHashTable.cpp" | ||||
| #include "JsonParser/JsonObjectBase.cpp" | ||||
| #include "JsonParser/Jsmn.cpp" | ||||
							
								
								
									
										65
									
								
								JsonParser.h
									
									
									
									
									
								
							
							
						
						
									
										65
									
								
								JsonParser.h
									
									
									
									
									
								
							| @@ -3,67 +3,4 @@ | ||||
| * Benoit Blanchon 2014 - MIT License | ||||
| */ | ||||
|  | ||||
| #ifndef __JSONPARSER_H | ||||
| #define __JSONPARSER_H | ||||
|  | ||||
| #include "JsonHashTable.h" | ||||
| #include "JsonArray.h" | ||||
|  | ||||
| /* | ||||
| * The JSON parser. | ||||
| * | ||||
| * You need to specifiy the number of token to be allocated for that parser. | ||||
| * Values from 16 to 32 are recommended. | ||||
| * The parser size will be MAX_TOKEN*8 bytes. | ||||
| * Don't forget that the memory size of standard Arduino board is only 2KB | ||||
| * | ||||
| * CAUTION: JsonArray and JsonHashTable contain pointers to tokens of the | ||||
| * JsonParser, so they need the JsonParser to be in memory to work. | ||||
| * As a result, you must not create JsonArray and JsonHashTable that have a  | ||||
| * longer life that the JsonParser. | ||||
| */ | ||||
| template <int MAX_TOKENS> | ||||
| class JsonParser | ||||
| { | ||||
| public: | ||||
|  | ||||
| 	/* | ||||
| 	* Parse the JSON string and return a array. | ||||
| 	* | ||||
| 	* The content of the string may be altered to add '\0' at the | ||||
| 	* end of string tokens | ||||
| 	*/  | ||||
| 	JsonArray parseArray(char* json) | ||||
| 	{ | ||||
| 		return JsonArray(json, parse(json)); | ||||
| 	} | ||||
|  | ||||
| 	/* | ||||
| 	* Parse the JSON string and return a array. | ||||
| 	* | ||||
| 	* The content of the string may be altered to add '\0' at the | ||||
| 	* end of string tokens | ||||
| 	*/ | ||||
| 	JsonHashTable parseHashTable(char* json) | ||||
| 	{ | ||||
| 		return JsonHashTable(json, parse(json)); | ||||
| 	} | ||||
|  | ||||
| private: | ||||
|  | ||||
| 	jsmntok_t* parse(char* json) | ||||
| 	{ | ||||
| 		jsmn_parser parser; | ||||
| 		jsmn_init(&parser); | ||||
|  | ||||
| 		if (JSMN_SUCCESS != jsmn_parse(&parser, json, tokens, MAX_TOKENS)) | ||||
| 			return 0; | ||||
|  | ||||
| 		return tokens; | ||||
| 	} | ||||
|  | ||||
| 	jsmntok_t tokens[MAX_TOKENS]; | ||||
| }; | ||||
|  | ||||
| #endif | ||||
|  | ||||
| #include "JsonParser/JsonParser.h" | ||||
| @@ -7,7 +7,7 @@ | ||||
| #ifndef __JSONOBJECTBASE_H | ||||
| #define __JSONOBJECTBASE_H | ||||
| 
 | ||||
| #include "utility/jsmn.h" | ||||
| #include "jsmn.h" | ||||
| 
 | ||||
| class JsonObjectBase | ||||
| { | ||||
							
								
								
									
										69
									
								
								JsonParser/JsonParser.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										69
									
								
								JsonParser/JsonParser.h
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,69 @@ | ||||
| /* | ||||
| * malloc-free JSON parser for Arduino | ||||
| * Benoit Blanchon 2014 - MIT License | ||||
| */ | ||||
|  | ||||
| #ifndef __JSONPARSER_H | ||||
| #define __JSONPARSER_H | ||||
|  | ||||
| #include "JsonHashTable.h" | ||||
| #include "JsonArray.h" | ||||
|  | ||||
| /* | ||||
| * The JSON parser. | ||||
| * | ||||
| * You need to specifiy the number of token to be allocated for that parser. | ||||
| * Values from 16 to 32 are recommended. | ||||
| * The parser size will be MAX_TOKEN*8 bytes. | ||||
| * Don't forget that the memory size of standard Arduino board is only 2KB | ||||
| * | ||||
| * CAUTION: JsonArray and JsonHashTable contain pointers to tokens of the | ||||
| * JsonParser, so they need the JsonParser to be in memory to work. | ||||
| * As a result, you must not create JsonArray and JsonHashTable that have a  | ||||
| * longer life that the JsonParser. | ||||
| */ | ||||
| template <int MAX_TOKENS> | ||||
| class JsonParser | ||||
| { | ||||
| public: | ||||
|  | ||||
| 	/* | ||||
| 	* Parse the JSON string and return a array. | ||||
| 	* | ||||
| 	* The content of the string may be altered to add '\0' at the | ||||
| 	* end of string tokens | ||||
| 	*/  | ||||
| 	JsonArray parseArray(char* json) | ||||
| 	{ | ||||
| 		return JsonArray(json, parse(json)); | ||||
| 	} | ||||
|  | ||||
| 	/* | ||||
| 	* Parse the JSON string and return a array. | ||||
| 	* | ||||
| 	* The content of the string may be altered to add '\0' at the | ||||
| 	* end of string tokens | ||||
| 	*/ | ||||
| 	JsonHashTable parseHashTable(char* json) | ||||
| 	{ | ||||
| 		return JsonHashTable(json, parse(json)); | ||||
| 	} | ||||
|  | ||||
| private: | ||||
|  | ||||
| 	jsmntok_t* parse(char* json) | ||||
| 	{ | ||||
| 		jsmn_parser parser; | ||||
| 		jsmn_init(&parser); | ||||
|  | ||||
| 		if (JSMN_SUCCESS != jsmn_parse(&parser, json, tokens, MAX_TOKENS)) | ||||
| 			return 0; | ||||
|  | ||||
| 		return tokens; | ||||
| 	} | ||||
|  | ||||
| 	jsmntok_t tokens[MAX_TOKENS]; | ||||
| }; | ||||
|  | ||||
| #endif | ||||
|  | ||||
| @@ -84,22 +84,22 @@ | ||||
|     </Link> | ||||
|   </ItemDefinitionGroup> | ||||
|   <ItemGroup> | ||||
|     <ClInclude Include="..\JsonArray.h" /> | ||||
|     <ClInclude Include="..\JsonHashTable.h" /> | ||||
|     <ClInclude Include="..\JsonObjectBase.h" /> | ||||
|     <ClInclude Include="..\JsonParser.h" /> | ||||
|     <ClInclude Include="..\utility\jsmn.h" /> | ||||
|   </ItemGroup> | ||||
|   <ItemGroup> | ||||
|     <ClCompile Include="..\JsonArray.cpp" /> | ||||
|     <ClCompile Include="..\JsonHashTable.cpp" /> | ||||
|     <ClCompile Include="..\JsonObjectBase.cpp" /> | ||||
|     <ClCompile Include="..\utility\jsmn.cpp" /> | ||||
|     <ClCompile Include="..\JsonParser\jsmn.cpp" /> | ||||
|     <ClCompile Include="..\JsonParser\JsonArray.cpp" /> | ||||
|     <ClCompile Include="..\JsonParser\JsonHashTable.cpp" /> | ||||
|     <ClCompile Include="..\JsonParser\JsonObjectBase.cpp" /> | ||||
|     <ClCompile Include="TestArrayExample.cpp" /> | ||||
|     <ClCompile Include="TestArrays.cpp" /> | ||||
|     <ClCompile Include="TestHashTableExample.cpp" /> | ||||
|     <ClCompile Include="TestGbathreeStrings.cpp" /> | ||||
|   </ItemGroup> | ||||
|   <ItemGroup> | ||||
|     <ClInclude Include="..\JsonParser\jsmn.h" /> | ||||
|     <ClInclude Include="..\JsonParser\JsonArray.h" /> | ||||
|     <ClInclude Include="..\JsonParser\JsonHashTable.h" /> | ||||
|     <ClInclude Include="..\JsonParser\JsonObjectBase.h" /> | ||||
|     <ClInclude Include="..\JsonParser\JsonParser.h" /> | ||||
|   </ItemGroup> | ||||
|   <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" /> | ||||
|   <ImportGroup Label="ExtensionTargets"> | ||||
|   </ImportGroup> | ||||
| @@ -15,35 +15,6 @@ | ||||
|     </Filter> | ||||
|   </ItemGroup> | ||||
|   <ItemGroup> | ||||
|     <ClInclude Include="..\JsonArray.h"> | ||||
|       <Filter>Header Files</Filter> | ||||
|     </ClInclude> | ||||
|     <ClInclude Include="..\JsonHashTable.h"> | ||||
|       <Filter>Header Files</Filter> | ||||
|     </ClInclude> | ||||
|     <ClInclude Include="..\JsonObjectBase.h"> | ||||
|       <Filter>Header Files</Filter> | ||||
|     </ClInclude> | ||||
|     <ClInclude Include="..\JsonParser.h"> | ||||
|       <Filter>Header Files</Filter> | ||||
|     </ClInclude> | ||||
|     <ClInclude Include="..\utility\jsmn.h"> | ||||
|       <Filter>Header Files</Filter> | ||||
|     </ClInclude> | ||||
|   </ItemGroup> | ||||
|   <ItemGroup> | ||||
|     <ClCompile Include="..\JsonArray.cpp"> | ||||
|       <Filter>Source Files</Filter> | ||||
|     </ClCompile> | ||||
|     <ClCompile Include="..\JsonHashTable.cpp"> | ||||
|       <Filter>Source Files</Filter> | ||||
|     </ClCompile> | ||||
|     <ClCompile Include="..\JsonObjectBase.cpp"> | ||||
|       <Filter>Source Files</Filter> | ||||
|     </ClCompile> | ||||
|     <ClCompile Include="..\utility\jsmn.cpp"> | ||||
|       <Filter>Source Files</Filter> | ||||
|     </ClCompile> | ||||
|     <ClCompile Include="TestHashTableExample.cpp"> | ||||
|       <Filter>Source Files</Filter> | ||||
|     </ClCompile> | ||||
| @@ -56,5 +27,34 @@ | ||||
|     <ClCompile Include="TestArrays.cpp"> | ||||
|       <Filter>Source Files</Filter> | ||||
|     </ClCompile> | ||||
|     <ClCompile Include="..\JsonParser\jsmn.cpp"> | ||||
|       <Filter>Source Files</Filter> | ||||
|     </ClCompile> | ||||
|     <ClCompile Include="..\JsonParser\JsonArray.cpp"> | ||||
|       <Filter>Source Files</Filter> | ||||
|     </ClCompile> | ||||
|     <ClCompile Include="..\JsonParser\JsonHashTable.cpp"> | ||||
|       <Filter>Source Files</Filter> | ||||
|     </ClCompile> | ||||
|     <ClCompile Include="..\JsonParser\JsonObjectBase.cpp"> | ||||
|       <Filter>Source Files</Filter> | ||||
|     </ClCompile> | ||||
|   </ItemGroup> | ||||
|   <ItemGroup> | ||||
|     <ClInclude Include="..\JsonParser\jsmn.h"> | ||||
|       <Filter>Header Files</Filter> | ||||
|     </ClInclude> | ||||
|     <ClInclude Include="..\JsonParser\JsonArray.h"> | ||||
|       <Filter>Header Files</Filter> | ||||
|     </ClInclude> | ||||
|     <ClInclude Include="..\JsonParser\JsonHashTable.h"> | ||||
|       <Filter>Header Files</Filter> | ||||
|     </ClInclude> | ||||
|     <ClInclude Include="..\JsonParser\JsonObjectBase.h"> | ||||
|       <Filter>Header Files</Filter> | ||||
|     </ClInclude> | ||||
|     <ClInclude Include="..\JsonParser\JsonParser.h"> | ||||
|       <Filter>Header Files</Filter> | ||||
|     </ClInclude> | ||||
|   </ItemGroup> | ||||
| </Project> | ||||
							
								
								
									
										25
									
								
								JsonParserTests/TestHashGenerator.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										25
									
								
								JsonParserTests/TestHashGenerator.cpp
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,25 @@ | ||||
| #include "stdafx.h" | ||||
| #include "CppUnitTest.h" | ||||
|  | ||||
| using namespace Microsoft::VisualStudio::CppUnitTestFramework; | ||||
|  | ||||
| namespace ArduinoJsonParserTests | ||||
| { | ||||
| 	TEST_CLASS(TestHashGenerator) | ||||
| 	{ | ||||
| 	public: | ||||
| 		 | ||||
| 		TEST_METHOD(TestMethod1) | ||||
| 		{ | ||||
|             JsonArray<5> arr; | ||||
|             arr.Add(1); | ||||
|             arr.Add("Hi!"); | ||||
|  | ||||
|             JsonHashTable<4> hash; | ||||
|             hash.Add("key1", 1); | ||||
|             hash.Add("key2", "Hello!"); | ||||
|             hash.Add("key3", arr); | ||||
| 		} | ||||
|  | ||||
| 	}; | ||||
| } | ||||
		Reference in New Issue
	
	Block a user