|
3 | 3 |
|
4 | 4 | #ifndef NO_SERVER
|
5 | 5 |
|
6 |
| -#include <cstdint> |
7 | 6 | #include <vector>
|
8 | 7 | #include <string>
|
9 | 8 | #include <cstring>
|
10 | 9 |
|
11 | 10 | namespace comm {
|
12 | 11 |
|
13 | 12 | /**
|
14 |
| - * @brief ByteArray as a simple wrapper over std::vector<uint8_t> |
| 13 | + * @brief ByteArray as a simple wrapper over std::vector<char> |
15 | 14 | */
|
16 |
| -class ByteArray : public std::vector<uint8_t> { |
| 15 | +class ByteArray : public std::vector<char> { |
17 | 16 | public:
|
18 | 17 | static const std::size_t DEFAULT_SIZE_HINT = 1024;
|
19 | 18 |
|
20 | 19 | ByteArray(const char* data)
|
21 |
| - : std::vector<uint8_t>(reinterpret_cast<const uint8_t*>(data), |
22 |
| - reinterpret_cast<const uint8_t*>(data + std::strlen(data))) |
| 20 | + : std::vector<char>(data, data + std::strlen(data)) |
23 | 21 | {}
|
24 | 22 |
|
25 | 23 | ByteArray(const char* data, std::size_t size)
|
26 |
| - : std::vector<uint8_t>(reinterpret_cast<const uint8_t*>(data), |
27 |
| - reinterpret_cast<const uint8_t*>(data + size)) |
| 24 | + : std::vector<char>(data, data + size) |
28 | 25 | {}
|
29 | 26 |
|
30 | 27 | ByteArray(std::size_t size_hint = DEFAULT_SIZE_HINT) {
|
31 | 28 | reserve(size_hint);
|
32 | 29 | }
|
33 | 30 |
|
34 | 31 | template<typename Iterator>
|
35 |
| - ByteArray(Iterator first, Iterator last): std::vector<uint8_t>(first, last) {} |
| 32 | + ByteArray(Iterator first, Iterator last): std::vector<char>(first, last) {} |
36 | 33 |
|
37 | 34 | void append(const ByteArray& appendix) {
|
38 | 35 | insert(end(), appendix.begin(), appendix.end());
|
39 | 36 | }
|
40 | 37 |
|
41 |
| - void append(uint8_t b) { |
| 38 | + void append(char b) { |
42 | 39 | push_back(b);
|
43 | 40 | }
|
44 | 41 |
|
@@ -72,8 +69,8 @@ class ByteArray : public std::vector<uint8_t> {
|
72 | 69 | template<typename T>
|
73 | 70 | static uint32_t calc_check_sum(const T& iterable) {
|
74 | 71 | uint32_t sum = 0;
|
75 |
| - for (uint8_t c : iterable) { |
76 |
| - sum += static_cast<unsigned int>(c); |
| 72 | + for (char c : iterable) { |
| 73 | + sum += static_cast<unsigned int>(static_cast<unsigned char>(c)); |
77 | 74 | }
|
78 | 75 | return sum;
|
79 | 76 | }
|
|
0 commit comments