libhomegear-base  0.7
Base library for Homegear and Homegear family modules.
BitReaderWriter.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 BITREADERWRITER_H_
32 #define BITREADERWRITER_H_
33 
34 #include <vector>
35 #include <cstdint>
36 
37 namespace BaseLib
38 {
39 
41 {
42 public:
43  virtual ~BitReaderWriter();
44 
53  static std::vector<uint8_t> getPosition(const std::vector<uint8_t>& data, uint32_t position, uint32_t size);
54 
63  static std::vector<uint8_t> getPosition(const std::vector<char>& data, uint32_t position, uint32_t size);
64 
73  static uint8_t getPosition8(const std::vector<uint8_t>& data, uint32_t position, uint32_t size);
74 
83  static uint16_t getPosition16(const std::vector<uint8_t>& data, uint32_t position, uint32_t size);
84 
93  static uint32_t getPosition32(const std::vector<uint8_t>& data, uint32_t position, uint32_t size);
94 
103  static uint64_t getPosition64(const std::vector<uint8_t>& data, uint32_t position, uint32_t size);
104 
113  static void setPositionLE(uint32_t position, uint32_t size, std::vector<uint8_t>& target, const std::vector<uint8_t>& source);
114 
123  static void setPositionLE(uint32_t position, uint32_t size, std::vector<char>& target, const std::vector<uint8_t>& source);
124 
133  static void setPositionBE(uint32_t position, uint32_t size, std::vector<uint8_t>& target, const std::vector<uint8_t>& source);
134 
143  static void setPositionBE(uint32_t position, uint32_t size, std::vector<char>& target, const std::vector<uint8_t>& source);
144 private:
145  static const uint8_t _bitMaskGet[8];
146  static const uint8_t _bitMaskSetSource[9];
147  static const uint8_t _bitMaskSetTargetStart[8];
148  static const uint8_t _bitMaskSetTargetEnd[8];
149 
150  BitReaderWriter();
151 };
152 
153 }
154 #endif
Definition: BitReaderWriter.h:40
static std::vector< uint8_t > getPosition(const std::vector< uint8_t > &data, uint32_t position, uint32_t size)
Reads any number of bits at any position from a byte array.
Definition: BitReaderWriter.cpp:43
Definition: BaseLib.cpp:34
static uint8_t getPosition8(const std::vector< uint8_t > &data, uint32_t position, uint32_t size)
Reads up to 8 bits at any position from a byte array and returns it as an uint8_t.
Definition: BitReaderWriter.cpp:161
static uint32_t getPosition32(const std::vector< uint8_t > &data, uint32_t position, uint32_t size)
Reads up to 32 bits at any position from a byte array and returns it as an uint32_t.
Definition: BitReaderWriter.cpp:223
static uint64_t getPosition64(const std::vector< uint8_t > &data, uint32_t position, uint32_t size)
Reads up to 64 bits at any position from a byte array and returns it as an uint64_t.
Definition: BitReaderWriter.cpp:258
static void setPositionLE(uint32_t position, uint32_t size, std::vector< uint8_t > &target, const std::vector< uint8_t > &source)
Sets any number of bits at any position in a byte array.
Definition: BitReaderWriter.cpp:293
static uint16_t getPosition16(const std::vector< uint8_t > &data, uint32_t position, uint32_t size)
Reads up to 16 bits at any position from a byte array and returns it as an uint16_t.
Definition: BitReaderWriter.cpp:187
static void setPositionBE(uint32_t position, uint32_t size, std::vector< uint8_t > &target, const std::vector< uint8_t > &source)
Sets any number of bits at any position in a byte array.
Definition: BitReaderWriter.cpp:409