libhomegear-base  0.7
Base library for Homegear and Homegear family modules.
RpcDecoder.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 RPCDECODER_H_
32 #define RPCDECODER_H_
33 
34 #include "../Variable.h"
35 #include "../Exception.h"
36 #include "BinaryDecoder.h"
37 #include "RpcHeader.h"
38 
39 #include <memory>
40 #include <vector>
41 #include <cstring>
42 #include <cmath>
43 
44 namespace BaseLib {
45 
46 class SharedObjects;
47 
48 namespace Rpc {
49 
51  public:
52  explicit RpcDecoderException(std::string message) : BaseLib::Exception(message) {}
53 };
54 
55 class RpcDecoder {
56  public:
57  RpcDecoder();
58  explicit RpcDecoder(bool ansi, bool setInteger32 = true);
59 
63  explicit RpcDecoder(BaseLib::SharedObjects *baseLib);
64 
68  RpcDecoder(BaseLib::SharedObjects *baseLib, bool ansi, bool setInteger32 = true);
69  ~RpcDecoder() = default;
70 
71  std::shared_ptr<RpcHeader> decodeHeader(const std::vector<char> &packet);
72  std::shared_ptr<RpcHeader> decodeHeader(const std::vector<uint8_t> &packet);
73  std::shared_ptr<std::vector<std::shared_ptr<Variable>>> decodeRequest(const std::vector<char> &packet, std::string &methodName);
74  std::shared_ptr<std::vector<std::shared_ptr<Variable>>> decodeRequest(const std::vector<uint8_t> &packet, std::string &methodName);
75  std::shared_ptr<Variable> decodeResponse(const std::vector<char> &packet, uint32_t offset = 0);
76  std::shared_ptr<Variable> decodeResponse(const std::vector<uint8_t> &packet, uint32_t offset = 0);
77  private:
78  bool _ansi = false;
79  std::unique_ptr<BinaryDecoder> _decoder;
80  bool _setInteger32 = true;
81 
82  std::shared_ptr<Variable> decodeParameter(const std::vector<char> &packet, uint32_t &position);
83  std::shared_ptr<Variable> decodeParameter(const std::vector<uint8_t> &packet, uint32_t &position);
84  VariableType decodeType(const std::vector<char> &packet, uint32_t &position);
85  VariableType decodeType(const std::vector<uint8_t> &packet, uint32_t &position);
86  std::shared_ptr<Array> decodeArray(const std::vector<char> &packet, uint32_t &position);
87  std::shared_ptr<Array> decodeArray(const std::vector<uint8_t> &packet, uint32_t &position);
88  std::shared_ptr<Struct> decodeStruct(const std::vector<char> &packet, uint32_t &position);
89  std::shared_ptr<Struct> decodeStruct(const std::vector<uint8_t> &packet, uint32_t &position);
90 };
91 }
92 }
93 #endif
This is the base library main class.
Definition: BaseLib.h:95
Definition: RpcDecoder.h:55
Definition: BaseLib.cpp:34
VariableType
Definition: Variable.h:49
Definition: RpcDecoder.h:50
RpcDecoderException(std::string message)
Definition: RpcDecoder.h:52
Base class for all exceptions defined in Homegear.
Definition: Exception.h:41