DiscordCoreAPI
A Discord bot library written in C++, with custom asynchronous coroutines.
Loading...
Searching...
No Matches
DataParsingFunctions.hpp
Go to the documentation of this file.
1/*
2 DiscordCoreAPI, A bot library for Discord, written in C++, and featuring explicit multithreading through the usage of custom, asynchronous C++ CoRoutines.
3
4 Copyright 2021, 2022 Chris M. (RealTimeChris)
5
6 This library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Lesser General Public
8 License as published by the Free Software Foundation; either
9 version 2.1 of the License, or (at your option) any later version.
10
11 This library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Lesser General Public License for more details.
15
16 You should have received a copy of the GNU Lesser General Public
17 License along with this library; if not, write to the Free Software
18 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
19 USA
20*/
21/// DataParsingFunctions.hpp - Header file for the data-parsing functions.
22/// Oct 1, 2021
23/// https://discordcoreapi.com
24/// \file DataParsingFunctions.hpp
25
26#ifndef DATA_PARSING_FUNCTIONS
27#define DATA_PARSING_FUNCTIONS
28
29#include <simdjson.h>
30
31namespace DiscordCoreAPI {
32
33 static std::map<int32_t, std::string> theErrors{ { 0, "SUCCESS" }, { 1, "CAPACITY" }, { 2, "MEMALLOC" }, { 3, "TAPE_ERRPR" }, { 4, "DEPTH_ERROR" }, { 5, "STRING_ERROR" },
34 { 6, "T_ATOM_ERROR" }, { 7, "F_ATOM_ERROR" }, { 8, "N_ATOM_ERROR" }, { 9, "NUMBER_ERROR" }, { 10, "UTF8_ERROR" }, { 11, "UNINITIALIZED" }, { 12, "EMPTY" },
35 { 13, "UNESCAPED_CHARS" }, { 14, "UNCLOSED_STRING" }, { 15, "UNSUPPORTED_ARCHITECTURE" }, { 16, "INCORRECT_TYPE" }, { 17, "NUMBER_OUT_OF_RANGE" },
36 { 18, "INDEX_OUT_OF_BOUNDS" }, { 19, "NO_SUCH_FIELD" }, { 20, "IO_ERROR" }, { 21, "INVALID_JSON_POINTER" }, { 22, "INVALID_URI_FRAGMENT" }, { 23, "UNEXPECTED_ERROR" },
37 { 24, "PARSER_IN_USE" }, { 25, "OUT_OF_ORDER_ITERATION" }, { 26, "INSUFFICIENT_PADDING" }, { 27, "INCOMPLETE_ARRAY_OR_OBJECT" }, { 28, "SCALAR_DOCUMENT_AS_VALUE" },
38 { 29, "OUT_OF_BOUNDS" }, { 30, "NUM_ERROR_CODES " } };
39
40 struct JsonParseError : public std::runtime_error {
41 explicit JsonParseError(int32_t theCode);
42 };
43
44 struct DiscordCoreAPI_Dll ObjectReturnData {
45 simdjson::ondemand::value theObject{};
46 bool didItSucceed{ false };
47 };
48
49 struct DiscordCoreAPI_Dll ArrayReturnData {
50 simdjson::ondemand::array theArray{};
51 bool didItSucceed{ false };
52 };
53
54 Snowflake getId(simdjson::ondemand::value jsonObjectData, const char* theKey);
55
56 bool getBool(simdjson::ondemand::value jsonData, const char* theKey);
57
58 uint8_t getUint8(simdjson::ondemand::value jsonData, const char* theKey);
59
60 uint16_t getUint16(simdjson::ondemand::value jsonData, const char* theKey);
61
62 uint32_t getUint32(simdjson::ondemand::value jsonData, const char* theKey);
63
64 float getFloat(simdjson::ondemand::value jsonData, const char* theKey);
65
66 uint64_t getUint64(simdjson::ondemand::value jsonData, const char* theKey);
67
68 std::string getString(simdjson::ondemand::value jsonData, const char* theKey);
69
70 ObjectReturnData getObject(ArrayReturnData jsonObjectData, size_t objectIndex, std::source_location theLocation = std::source_location::current());
71
72 ObjectReturnData getObject(simdjson::ondemand::value jsonObjectData, const char* objectName, std::source_location theLocation = std::source_location::current());
73
74 ObjectReturnData getObject(ObjectReturnData jsonObjectData, const char* objectName, std::source_location theLocation = std::source_location::current());
75
76 ArrayReturnData getArray(ObjectReturnData jsonObjectData, const char* arrayName);
77
78 ArrayReturnData getArray(simdjson::ondemand::value jsonObjectData, const char* arrayName);
79
80};
81#endif
The main namespace for this library.