Keyple Util C++ Library 2.0.0
Reference Terminal Reader API for C++
ByteArrayUtil.h
Go to the documentation of this file.
1/**************************************************************************************************
2 * Copyright (c) 2021 Calypso Networks Association https://calypsonet.org/ *
3 * *
4 * See the NOTICE file(s) distributed with this work for additional information regarding *
5 * copyright ownership. *
6 * *
7 * This program and the accompanying materials are made available under the terms of the Eclipse *
8 * Public License 2.0 which is available at http://www.eclipse.org/legal/epl-2.0 *
9 * *
10 * SPDX-License-Identifier: EPL-2.0 *
11 **************************************************************************************************/
12
13#pragma once
14
15#include <memory>
16#include <stdexcept>
17#include <string>
18#include <vector>
19
20/* Util */
21#include "Pattern.h"
22
23/* Core */
24#include "KeypleUtilExport.h"
25
26namespace keyple {
27namespace core {
28namespace util {
29
34public:
46 static bool isValidHexString(const std::string& hex);
47
56 static const std::string normalizeHexString(const std::string& hex);
57
72 static std::vector<uint8_t> fromHex(const std::string& hex);
73
87 static uint8_t hexToByte(const std::string& hex);
88
102 static uint16_t hexToShort(const std::string& hex);
103
121 static uint32_t hexToInt(const std::string& hex);
122
136 static uint64_t hexToLong(const std::string& hex);
137
145 static std::string toHex(const std::vector<char>& tab);
146
154 static std::string toHex(const std::vector<uint8_t>& tab);
155
163 static const std::string toHex(const uint8_t val);
164
172 static const std::string toHex(const uint16_t val);
173
181 static const std::string toHex(const uint32_t val);
182
190 static const std::string toHex(const uint64_t val) ;
191
205 static int twoBytesToInt(const std::vector<uint8_t>& bytes, const int offset);
206
224 static int twoBytesSignedToInt(const std::vector<uint8_t>& bytes, const int offset);
225
239 static int threeBytesToInt(const std::vector<uint8_t>& bytes, const int offset);
240
258 static int threeBytesSignedToInt(const std::vector<uint8_t>& bytes, const int offset);
259
273 static int fourBytesToInt(const std::vector<uint8_t>& bytes, const int offset);
274
275private:
279 static const std::vector<std::string> mByteToHex;
280
284 static const std::vector<uint8_t> mHexToNibble;
285
289 static void checkBytesToIntConversionParams(const int size,
290 const std::vector<uint8_t>& bytes,
291 const int offset);
292};
293
294}
295}
296}
#define KEYPLEUTIL_API