libhomegear-base  0.7
Base library for Homegear and Homegear family modules.
JsonDecoder.h
Go to the documentation of this file.
1 /* Copyright 2013-2019 Homegear GmbH
2  *
3  * libhomegear-base is free software: you can redistribute it and/or
4  * modify it under the terms of the GNU Lesser General Public License as
5  * published by the Free Software Foundation, either version 3 of the
6  * License, or (at your option) any later version.
7  *
8  * libhomegear-base is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * GNU Lesser General Public License for more details.
12  *
13  * You should have received a copy of the GNU Lesser General Public
14  * License along with libhomegear-base. If not, see
15  * <http://www.gnu.org/licenses/>.
16  *
17  * In addition, as a special exception, the copyright holders give
18  * permission to link the code of portions of this program with the
19  * OpenSSL library under certain conditions as described in each
20  * individual source file, and distribute linked combinations
21  * including the two.
22  * You must obey the GNU Lesser General Public License in all respects
23  * for all of the code used other than OpenSSL. If you modify
24  * file(s) with this exception, you may extend this exception to your
25  * version of the file(s), but you are not obligated to do so. If you
26  * do not wish to do so, delete this exception statement from your
27  * version. If you delete this exception statement from all source
28  * files in the program, then also delete it here.
29  */
30 
31 #ifndef JSONDECODER_H_
32 #define JSONDECODER_H_
33 
34 #include "../Exception.h"
35 #include "../Variable.h"
36 #if __GNUC__ > 4
37 #include <codecvt>
38 #endif
39 
40 namespace BaseLib {
41 
42 class SharedObjects;
43 
44 namespace Rpc {
46  public:
47  explicit JsonDecoderException(std::string message) : BaseLib::Exception(message) {}
48 };
49 
50 class JsonDecoder {
51  public:
52  JsonDecoder() = default;
53  explicit JsonDecoder(BaseLib::SharedObjects *dummy) {};
54  virtual ~JsonDecoder() = default;
55 
56  static std::shared_ptr<Variable> decode(const std::string &json);
57  static std::shared_ptr<Variable> decode(const std::string &json, uint32_t &bytesRead);
58  static std::shared_ptr<Variable> decode(const std::vector<char> &json);
59  static std::shared_ptr<Variable> decode(const std::vector<char> &json, uint32_t &bytesRead);
60 
61  static std::string decodeString(const std::string &s);
62  private:
63  static inline bool posValid(const std::string &json, uint32_t pos);
64  static inline bool posValid(const std::vector<char> &json, uint32_t pos);
65  static void skipWhitespace(const std::string &json, uint32_t &pos);
66  static void skipWhitespace(const std::vector<char> &json, uint32_t &pos);
67  static void decodeObject(const std::string &json, uint32_t &pos, std::shared_ptr<Variable> &variable);
68  static void decodeObject(const std::vector<char> &json, uint32_t &pos, std::shared_ptr<Variable> &variable);
69  static void decodeArray(const std::string &json, uint32_t &pos, std::shared_ptr<Variable> &variable);
70  static void decodeArray(const std::vector<char> &json, uint32_t &pos, std::shared_ptr<Variable> &variable);
71  static void decodeString(const std::string &json, uint32_t &pos, std::shared_ptr<Variable> &value);
72  static void decodeString(const std::vector<char> &json, uint32_t &pos, std::shared_ptr<Variable> &value);
73  static void decodeString(const std::string &json, uint32_t &pos, std::string &s);
74  static void decodeString(const std::vector<char> &json, uint32_t &pos, std::string &s);
75  static bool decodeValue(const std::string &json, uint32_t &pos, std::shared_ptr<Variable> &value);
76  static bool decodeValue(const std::vector<char> &json, uint32_t &pos, std::shared_ptr<Variable> &value);
77  static void decodeBoolean(const std::string &json, uint32_t &pos, std::shared_ptr<Variable> &value);
78  static void decodeBoolean(const std::vector<char> &json, uint32_t &pos, std::shared_ptr<Variable> &value);
79  static void decodeNull(const std::string &json, uint32_t &pos, std::shared_ptr<Variable> &value);
80  static void decodeNull(const std::vector<char> &json, uint32_t &pos, std::shared_ptr<Variable> &value);
81  static bool decodeNumber(const std::string &json, uint32_t &pos, std::shared_ptr<Variable> &value);
82  static bool decodeNumber(const std::vector<char> &json, uint32_t &pos, std::shared_ptr<Variable> &value);
83 };
84 }
85 }
86 #endif
JsonDecoderException(std::string message)
Definition: JsonDecoder.h:47
JsonDecoder(BaseLib::SharedObjects *dummy)
Definition: JsonDecoder.h:53
This is the base library main class.
Definition: BaseLib.h:95
Definition: BaseLib.cpp:34
Definition: JsonDecoder.h:45
PVariable value
Definition: UiElements.h:217
Base class for all exceptions defined in Homegear.
Definition: Exception.h:41
Definition: JsonDecoder.h:50