8 #include <gsl/gsl_util> 15 template <
size_t size,
typename u
int>
16 inline std::array<uint8_t, size> uint_to_le_bytes(uint &&i) {
17 std::array<uint8_t, size> res{};
19 export_bits(i, res.begin(), 8,
false);
23 template <
size_t size,
typename u
int>
24 inline std::array<uint8_t, size> uint_to_be_bytes(uint &&i) {
25 std::array<uint8_t, size> res{};
27 export_bits(i, res.rbegin(), 8,
false);
31 template <
size_t size,
typename u
int>
32 inline uint le_bytes_to_uint(gsl::span<const uint8_t, size> bytes) {
37 import_bits(result, bytes.begin(), bytes.end(), 8,
false);
41 template <
size_t size,
typename u
int>
42 inline uint be_bytes_to_uint(gsl::span<const uint8_t, size> bytes) {
47 import_bits(result, bytes.rbegin(), bytes.rend(), 8,
false);
53 std::array<uint8_t, 8> result{};
54 *
reinterpret_cast<uint64_t *
>(result.data()) = htole64(number);
60 memcpy(&number, bytes.data(), 8);
61 return le64toh(number);
65 std::array<uint8_t, 8> result{};
66 *
reinterpret_cast<uint64_t *
>(result.data()) = htobe64(number);
72 memcpy(&number, bytes.data(), 8);
73 return be64toh(number);
78 return uint_to_le_bytes<16>(i);
82 gsl::span<const uint8_t, 16> bytes) {
83 return le_bytes_to_uint<16, boost::multiprecision::uint128_t>(bytes);
88 return uint_to_be_bytes<16>(i);
92 gsl::span<const uint8_t, 16> bytes) {
93 return be_bytes_to_uint<16, boost::multiprecision::uint128_t>(bytes);
98 return uint_to_le_bytes<32>(i);
102 gsl::span<const uint8_t, 32> bytes) {
103 return le_bytes_to_uint<32, boost::multiprecision::uint256_t>(bytes);
108 return uint_to_be_bytes<32>(i);
112 gsl::span<const uint8_t, 32> bytes) {
113 return be_bytes_to_uint<32, boost::multiprecision::uint256_t>(bytes);
boost::multiprecision::uint256_t uint256_t
uint64_t le_bytes_to_uint64(gsl::span< const uint8_t, 8 > bytes)
boost::multiprecision::uint256_t be_bytes_to_uint256(gsl::span< const uint8_t, 32 > bytes)
boost::multiprecision::uint128_t be_bytes_to_uint128(gsl::span< const uint8_t, 16 > bytes)
boost::multiprecision::uint128_t le_bytes_to_uint128(gsl::span< const uint8_t, 16 > bytes)
uint64_t be_bytes_to_uint64(gsl::span< const uint8_t, 8 > bytes)
boost::multiprecision::uint256_t le_bytes_to_uint256(gsl::span< const uint8_t, 32 > bytes)
std::array< uint8_t, 8 > uint64_to_be_bytes(uint64_t number)
std::array< uint8_t, 32 > uint256_to_be_bytes(const boost::multiprecision::uint256_t &i)
std::array< uint8_t, 16 > uint128_to_le_bytes(const boost::multiprecision::uint128_t &i)
std::array< uint8_t, 8 > uint64_to_le_bytes(uint64_t number)
boost::multiprecision::uint128_t uint128_t
std::array< uint8_t, 16 > uint128_to_be_bytes(const boost::multiprecision::uint128_t &i)
std::array< uint8_t, 32 > uint256_to_le_bytes(const boost::multiprecision::uint256_t &i)