Keyple Util C++ Library 2.3.0.5-SNAPSHOT
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 <cstdint>
16#include <memory>
17#include <stdexcept>
18#include <string>
19#include <vector>
20
21/* Util */
22#include "Pattern.h"
23
24/* Core */
25#include "KeypleUtilExport.h"
26
27namespace keyple {
28namespace core {
29namespace util {
30
35public:
47 static const std::vector<uint8_t> extractBytes(const std::vector<uint8_t>& src,
48 const int bitOffset,
49 const int nbBytes);
50
64 static const std::vector<uint8_t> extractBytes(const uint64_t src, const int nbBytes);
65
75 static uint16_t extractShort(const std::vector<uint8_t>& src, const int offset);
76
92 static uint32_t extractInt(const std::vector<uint8_t>& src,
93 const int offset,
94 const int nbBytes,
95 const bool isSigned);
96
112 static uint64_t extractLong(const std::vector<uint8_t>& src,
113 const int offset,
114 const int nbBytes,
115 const bool isSigned);
116
129 static void copyBytes(const uint64_t src,
130 std::vector<uint8_t>& dest,
131 const int offset,
132 const int nbBytes);
133
147 static bool isValidHexString(const std::string& hex);
148
158 static const std::string normalizeHexString(const std::string& hex);
159
175 static std::vector<uint8_t> fromHex(const std::string& hex);
176
185 static const std::string toHex(const std::vector<uint8_t>& src);
186
202 static int twoBytesToInt(const std::vector<uint8_t>& bytes, const int offset);
203
223 static int twoBytesSignedToInt(const std::vector<uint8_t>& bytes, const int offset);
224
240 static int threeBytesToInt(const std::vector<uint8_t>& bytes, const int offset);
241
261 static int threeBytesSignedToInt(const std::vector<uint8_t>& bytes, const int offset);
262
278 static int fourBytesToInt(const std::vector<uint8_t>& bytes, const int offset);
279};
280
281}
282}
283}
#define KEYPLEUTIL_API