41getUintX(
const void *buf, std::size_t bytes, ByteOrder endian)
45 case sizeof(std::uint64_t):
46 return {
gtoh(*(
const std::uint64_t *)buf, endian),
true};
47 case sizeof(std::uint32_t):
48 return {
gtoh(*(
const std::uint32_t *)buf, endian),
true};
49 case sizeof(std::uint16_t):
50 return {
gtoh(*(
const std::uint16_t *)buf, endian),
true};
51 case sizeof(std::uint8_t):
52 return {
gtoh(*(
const std::uint8_t *)buf, endian),
true};
59setUintX(std::uint64_t
val,
void *buf, std::size_t bytes, ByteOrder endian)
64 case sizeof(std::uint64_t):
67 case sizeof(std::uint32_t):
70 case sizeof(std::uint16_t):
73 case sizeof(std::uint8_t):
82printUintX(
const void *buf, std::size_t bytes, ByteOrder endian)
88 std::ostringstream out;
92 out.setf(std::ios::hex, std::ios::basefield);
95 return {out.str(),
true};
100 std::size_t chunk_size)
104 std::ostringstream out;
109 out.setf(std::ios::hex, std::ios::basefield);
112 size_t extra = bytes % chunk_size;
114 const uint8_t *ptr = (
const uint8_t *)buf;
117 if (endian == ByteOrder::big) {
119 ptr = ptr + bytes - 1;
126 out << (unsigned)*ptr;
135 while (bytes >= chunk_size) {
136 for (
int i = 0;
i < chunk_size;
i++) {
138 out << (unsigned)*ptr;
149 out << (unsigned)*ptr;
Copyright (c) 2024 - Pranith Kumar Copyright (c) 2020 Inria All rights reserved.
std::pair< std::string, bool > printUintX(const void *buf, std::size_t bytes, ByteOrder endian)
std::pair< std::uint64_t, bool > getUintX(const void *buf, std::size_t bytes, ByteOrder endian)
T gtoh(T value, ByteOrder guest_byte_order)
bool setUintX(std::uint64_t val, void *buf, std::size_t bytes, ByteOrder endian)
T htog(T value, ByteOrder guest_byte_order)
std::string printByteBuf(const void *buf, std::size_t bytes, ByteOrder endian, std::size_t chunk_size)