libhomegear-base  0.7
Base library for Homegear and Homegear family modules.
BinaryDecoder.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 BINARYDECODER_H_
32 #define BINARYDECODER_H_
33 
34 #include "Ansi.h"
35 #include "../Exception.h"
36 
37 #include <memory>
38 #include <cstring>
39 #include <vector>
40 #include <string>
41 
42 namespace BaseLib {
43 
44 class SharedObjects;
45 
47  public:
48  explicit BinaryDecoderException(std::string message) : BaseLib::Exception(message) {}
49 };
50 
52  public:
53  BinaryDecoder() = default;
54  explicit BinaryDecoder(bool ansi);
55 
59  explicit BinaryDecoder(BaseLib::SharedObjects *baseLib);
60 
64  BinaryDecoder(BaseLib::SharedObjects *baseLib, bool ansi);
65  ~BinaryDecoder() = default;
66 
67  static int32_t decodeInteger(const std::vector<char> &encodedData, uint32_t &position);
68  static int32_t decodeInteger(const std::vector<uint8_t> &encodedData, uint32_t &position);
69  static int64_t decodeInteger64(const std::vector<char> &encodedData, uint32_t &position);
70  static int64_t decodeInteger64(const std::vector<uint8_t> &encodedData, uint32_t &position);
71  static uint8_t decodeByte(const std::vector<char> &encodedData, uint32_t &position);
72  static uint8_t decodeByte(const std::vector<uint8_t> &encodedData, uint32_t &position);
73  std::string decodeString(const std::vector<char> &encodedData, uint32_t &position);
74  std::string decodeString(const std::vector<uint8_t> &encodedData, uint32_t &position);
75  static std::vector<uint8_t> decodeBinary(const std::vector<char> &encodedData, uint32_t &position);
76  static std::vector<uint8_t> decodeBinary(const std::vector<uint8_t> &encodedData, uint32_t &position);
77  static bool decodeBoolean(const std::vector<char> &encodedData, uint32_t &position);
78  static bool decodeBoolean(const std::vector<uint8_t> &encodedData, uint32_t &position);
79  static double decodeFloat(const std::vector<char> &encodedData, uint32_t &position);
80  static double decodeFloat(const std::vector<uint8_t> &encodedData, uint32_t &position);
81  protected:
82  bool _ansi = false;
83  std::shared_ptr<Ansi> _ansiConverter;
84 };
85 }
86 #endif
This is the base library main class.
Definition: BaseLib.h:95
Definition: BaseLib.cpp:34
Definition: BinaryDecoder.h:46
Definition: BinaryDecoder.h:51
std::shared_ptr< Ansi > _ansiConverter
Definition: BinaryDecoder.h:83
BinaryDecoderException(std::string message)
Definition: BinaryDecoder.h:48
Base class for all exceptions defined in Homegear.
Definition: Exception.h:41