6#include <kernel/util/pack.hpp>
11#include <kernel/util/math.hpp>
12#include <kernel/util/type_traits.hpp>
38 static void swap(
void* )
47 static void swap(
void* x)
49 u16& v = *
reinterpret_cast<u16*
>(x);
50 v =
u16(((v & 0x00FFULL) << 8) | ((v & 0xFF00ULL) >> 8));
57 static void swap(
void* x)
59 u32& v = *
reinterpret_cast<u32*
>(x);
60 v =
u32(((v & 0x000000FFULL) << 24) | ((v & 0x0000FF00ULL) << 8) |
61 ((v & 0x00FF0000ULL) >> 8) | ((v & 0xFF000000ULL) >> 24));
68 static void swap(
void* x)
70 u64& v = *
reinterpret_cast<u64*
>(x);
71 v = ((v & 0x00000000000000FFULL) << 56) | ((v & 0x000000000000FF00ULL) << 40) |
72 ((v & 0x0000000000FF0000ULL) << 24) | ((v & 0x00000000FF000000ULL) << 8) |
73 ((v & 0x000000FF00000000ULL) >> 8) | ((v & 0x0000FF0000000000ULL) >> 24) |
74 ((v & 0x00FF000000000000ULL) >> 40) | ((v & 0xFF00000000000000ULL) >> 56);
81 static void swap(
void* x)
84 u64* vv =
reinterpret_cast<u64*
>(x);
113 static constexpr uint zfp_header_mask = 7u;
146 template<
typename X_,
typename T_>
147 static std::size_t
xencode(
void* buf,
const T_* src,
const std::size_t count,
bool swap_bytes)
149 X_* x =
reinterpret_cast<X_*
>(buf);
152 for(std::size_t i(0); i < count; ++i)
154 x[i] =
xswap(
static_cast<X_
>(src[i]));
159 for(std::size_t i(0); i < count; ++i)
161 x[i] =
static_cast<X_
>(src[i]);
164 return count *
sizeof(X_);
197 template<
typename X_,
typename T_>
198 static std::size_t
xdecode(T_* dest,
const void* buf,
const std::size_t count,
bool swap_bytes)
200 const X_* x =
reinterpret_cast<const X_*
>(buf);
203 for(std::size_t i(0); i < count; ++i)
205 dest[i] =
static_cast<T_
>(
xswap(x[i]));
210 for(std::size_t i(0); i < count; ++i)
212 dest[i] =
static_cast<T_
>(x[i]);
215 return count *
sizeof(X_);
218 template<
typename T
class_,
bool signed_>
221 template<
typename T_>
224 return Pack::Type::None;
232 template<
typename T_>
238 case 2:
return Pack::Type::F16;
239 case 4:
return Pack::Type::F32;
240 case 8:
return Pack::Type::F64;
241 case 16:
return Pack::Type::F128;
242 default:
return Pack::Type::None;
246 template<
typename T_>
248 encode(
void* buf,
const T_* t,
const std::size_t count,
const Pack::Type pack_type,
bool swap_bytes)
252#ifdef FEAT_HAVE_PACK_TYPE_F16
253 case Pack::Type::F16:
return xencode<Pack::f16>(buf, t, count, swap_bytes);
255 case Pack::Type::F32:
return xencode<Pack::f32>(buf, t, count, swap_bytes);
256 case Pack::Type::F64:
return xencode<Pack::f64>(buf, t, count, swap_bytes);
257#ifdef FEAT_HAVE_PACK_TYPE_F128
258 case Pack::Type::F128:
return xencode<Pack::f128>(buf, t, count, swap_bytes);
260 default:
XABORTM(
"invalid data type conversion");
264 template<
typename T_>
266 decode(T_* t,
const void* buf,
const std::size_t count,
const Pack::Type pack_type,
bool swap_bytes)
270#ifdef FEAT_HAVE_PACK_TYPE_F16
271 case Pack::Type::F16:
return xdecode<Pack::f16>(t, buf, count, swap_bytes);
273 case Pack::Type::F32:
return xdecode<Pack::f32>(t, buf, count, swap_bytes);
274 case Pack::Type::F64:
return xdecode<Pack::f64>(t, buf, count, swap_bytes);
275#ifdef FEAT_HAVE_PACK_TYPE_F128
276 case Pack::Type::F128:
return xdecode<Pack::f128>(t, buf, count, swap_bytes);
278 default:
XABORTM(
"invalid data type conversion");
287 template<
typename T_>
292 case 1:
return Pack::Type::I8;
293 case 2:
return Pack::Type::I16;
294 case 4:
return Pack::Type::I32;
295 case 8:
return Pack::Type::I64;
296 default:
return Pack::Type::None;
300 template<
typename T_>
302 encode(
void* buf,
const T_* t,
const std::size_t count,
const Pack::Type pack_type,
bool swap_bytes)
306 case Pack::Type::I8:
return xencode<Pack::i8>(buf, t, count, swap_bytes);
307 case Pack::Type::I16:
return xencode<Pack::i16>(buf, t, count, swap_bytes);
308 case Pack::Type::I32:
return xencode<Pack::i32>(buf, t, count, swap_bytes);
309 case Pack::Type::I64:
return xencode<Pack::i64>(buf, t, count, swap_bytes);
310 default:
XABORTM(
"invalid data type conversion");
314 template<
typename T_>
316 decode(T_* t,
const void* buf,
const std::size_t count,
const Pack::Type pack_type,
bool swap_bytes)
320 case Pack::Type::I8:
return xdecode<Pack::i8>(t, buf, count, swap_bytes);
321 case Pack::Type::I16:
return xdecode<Pack::i16>(t, buf, count, swap_bytes);
322 case Pack::Type::I32:
return xdecode<Pack::i32>(t, buf, count, swap_bytes);
323 case Pack::Type::I64:
return xdecode<Pack::i64>(t, buf, count, swap_bytes);
324 default:
XABORTM(
"invalid data type conversion");
333 template<
typename T_>
338 case 1:
return Pack::Type::U8;
339 case 2:
return Pack::Type::U16;
340 case 4:
return Pack::Type::U32;
341 case 8:
return Pack::Type::U64;
342 default:
return Pack::Type::None;
346 template<
typename T_>
348 encode(
void* buf,
const T_* t,
const std::size_t count,
const Pack::Type pack_type,
bool swap_bytes)
352 case Pack::Type::U8:
return xencode<Pack::u8>(buf, t, count, swap_bytes);
353 case Pack::Type::U16:
return xencode<Pack::u16>(buf, t, count, swap_bytes);
354 case Pack::Type::U32:
return xencode<Pack::u32>(buf, t, count, swap_bytes);
355 case Pack::Type::U64:
return xencode<Pack::u64>(buf, t, count, swap_bytes);
356 default:
XABORTM(
"invalid data type conversion");
360 template<
typename T_>
362 decode(T_* t,
const void* buf,
const std::size_t count,
const Pack::Type pack_type,
bool swap_bytes)
366 case Pack::Type::U8:
return xdecode<Pack::u8>(t, buf, count, swap_bytes);
367 case Pack::Type::U16:
return xdecode<Pack::u16>(t, buf, count, swap_bytes);
368 case Pack::Type::U32:
return xdecode<Pack::u32>(t, buf, count, swap_bytes);
369 case Pack::Type::U64:
return xdecode<Pack::u64>(t, buf, count, swap_bytes);
370 default:
XABORTM(
"invalid data type conversion");
375 template<
typename T_>
406 template<
typename T_>
410 if(count <= std::size_t(0))
412 return std::size_t(0);
418 XASSERTM((pack_type & Pack::Type::Mask_T) != Pack::Type::None,
"invalid pack type");
419 XASSERTM((pack_type & Pack::Type::Mask_Z) != Pack::Type::Mask_Z,
"cannot encode compressed type");
455 template<
typename T_>
459 if(count <= std::size_t(0))
461 return std::size_t(0);
467 XASSERTM((pack_type & Pack::Type::Mask_T) != Pack::Type::None,
"invalid pack type");
468 XASSERTM((pack_type & Pack::Type::Mask_Z) != Pack::Type::Mask_Z,
"cannot decode compressed type");
502 if(count <= std::size_t(0))
504 return std::size_t(0);
508 zfp_type t = zfp_type::zfp_type_none;
511 case Pack::Type::PF32: t = zfp_type::zfp_type_float;
break;
512 case Pack::Type::PF64: t = zfp_type::zfp_type_double;
break;
513 default:
XABORTM(
"cannot encode compressed type; data typ not available");
515 XASSERT(t != zfp_type::zfp_type_none);
521 std::size_t x_size, y_size;
522 void* temp_arr =
nullptr;
526 y_size = count / x_size + 1;
529 if((
sizeof(std::size_t) >
sizeof(uint)) && (count > std::numeric_limits<uint>::max()))
530 XABORTM(
"cannot encode compressed type; array size to big for internal data");
534 field = zfp_field_2d(temp_arr, t, (uint)x_size, (uint)y_size);
536 zfp = zfp_stream_open(NULL);
538 zfp_stream_set_accuracy(zfp, tolerance);
540 bytes = zfp_stream_maximum_size(zfp, field);
543 zfp_field_free(field);
544 zfp_stream_close(zfp);
552 XABORTM(
"cannot encode compressed type; zfp not available");
553 return std::size_t(0);
559 if((type & Pack::Type::Mask_P) != Pack::Type::None)
567 if((type & Pack::Type::Mask_Z) != Pack::Type::None)
569 return std::size_t(::compressBound(uLong(raw_size)));
572 XASSERTM((type & Pack::Type::Mask_Z) == Pack::Type::None,
"cannot estimate compressed size; zlib not available");
579 template<
typename T_>
583 const std::size_t buf_size,
584 const std::size_t count,
589 if(count <= std::size_t(0))
591 return std::size_t(0);
598 const Pack::Type raw_type = pack_type & Pack::Type::Mask_T;
601 if((pack_type & (Pack::Type::Mask_Z | Pack::Type::Mask_P)) == Pack::Type::None)
603 return encode_raw(buf, src, count, raw_type, swap_bytes);
607 if((pack_type & Pack::Type::Mask_Z) == Pack::Type::Mask_Z)
609 return lossless_encode(buf, src, buf_size, count, pack_type, swap_bytes);
613 if((pack_type & Pack::Type::Mask_P) == Pack::Type::Mask_P)
615 return lossy_encode(buf, src, buf_size, count, pack_type, swap_bytes, tolerance);
618 return std::size_t(0);
646 template<
typename T_>
650 const std::size_t buf_size,
651 const std::size_t count,
656 const Pack::Type raw_type = pack_type & Pack::Type::Mask_T;
661 std::vector<char> tmp(raw_size);
664 encode_raw(tmp.data(), src, count, raw_type, swap_bytes);
667 uLongf dl =
static_cast<uLongf
>(buf_size);
668 uLong sl =
static_cast<uLong
>(raw_size);
671 Bytef* dbuf =
reinterpret_cast<Bytef*
>(buf);
672 const Bytef* sbuf =
reinterpret_cast<const Bytef*
>(tmp.data());
675 if(::compress(dbuf, &dl, sbuf, sl) != Z_OK)
676 XABORTM(
"zlib compression error");
679 return static_cast<std::size_t
>(dl);
688 XABORTM(
"cannot encode compressed type; zlib not available");
689 return std::size_t(0);
693 template<
typename T_>
697 const std::size_t count,
698 const std::size_t buf_size,
702 if(count <= std::size_t(0))
704 return std::size_t(0);
711 const Pack::Type raw_type = pack_type & Pack::Type::Mask_T;
714 if((pack_type & (Pack::Type::Mask_Z | Pack::Type::Mask_P)) == Pack::Type::None)
716 return decode_raw(dst, buf, count, raw_type, swap_bytes);
720 if((pack_type & Pack::Type::Mask_Z) == Pack::Type::Mask_Z)
722 return lossless_decode(dst, buf, count, buf_size, pack_type, swap_bytes);
726 if((pack_type & Pack::Type::Mask_P) == Pack::Type::Mask_P)
728 return lossy_decode(dst, buf, count, buf_size, pack_type, swap_bytes);
731 return std::size_t(0);
758 template<
typename T_>
762 const std::size_t count,
763 const std::size_t buf_size,
768 const Pack::Type raw_type = pack_type & Pack::Type::Mask_T;
772 std::size_t raw_size =
element_size(raw_type) * count + 1024u;
773 std::vector<char> tmp(raw_size);
776 uLongf dl =
static_cast<uLongf
>(raw_size);
777 uLong sl =
static_cast<uLong
>(buf_size);
780 Bytef* dbuf =
reinterpret_cast<Bytef*
>(tmp.data());
781 const Bytef* sbuf =
reinterpret_cast<const Bytef*
>(buf);
784 if(::uncompress2(dbuf, &dl, sbuf, &sl) != Z_OK)
785 XABORTM(
"zlib decompression error");
788 decode_raw(dst, tmp.data(), count, raw_type, swap_bytes);
791 return static_cast<std::size_t
>(sl);
800 XABORTM(
"cannot decode compressed type; zlib not available");
801 return std::size_t(0);
838 template<
typename T_>
842 const std::size_t buf_size,
843 const std::size_t count,
846 const double tolerance)
849 const Pack::Type raw_type = pack_type & Pack::Type::Mask_T;
853 zfp_type t = zfp_type::zfp_type_none;
856 case Pack::Type::PF32: t = zfp_type::zfp_type_float;
break;
857 case Pack::Type::PF64: t = zfp_type::zfp_type_double;
break;
858 default:
XABORTM(
"cannot encode compressed type; data typ not available");
860 XASSERT(t != zfp_type::zfp_type_none);
870 std::vector<char> tmp(raw_size);
873 encode_raw(tmp.data(), src, count, raw_type, swap_bytes);
878 std::size_t real_bytes;
880 std::size_t x_size, y_size;
883 if((
sizeof(std::size_t) >
sizeof(uint)) && (count > std::numeric_limits<uint>::max()))
884 XABORTM(
"cannot encode compressed type; array size to big for internal "
889 y_size = count / x_size;
891 y_size = count / x_size + 1;
894 field = zfp_field_2d(tmp.data(), t, (uint)x_size, (uint)y_size);
895 zfp = zfp_stream_open(NULL);
896 zfp_stream_set_accuracy(zfp, tolerance);
897 stream = stream_open(buf, buf_size);
898 zfp_stream_set_bit_stream(zfp, stream);
899 stream_rewind(stream);
901 zfp_write_header(zfp, field, zfp_header_mask);
903 real_bytes = zfp_compress(zfp, field);
906 zfp_field_free(field);
907 zfp_stream_close(zfp);
908 stream_close(stream);
920 XABORTM(
"cannot encode compressed type; zfp not available");
921 return std::size_t(0);
950 template<
typename T_>
954 const std::size_t count,
955 const std::size_t buf_size,
960 const Pack::Type raw_type = pack_type & Pack::Type::Mask_T;
963 zfp_type t = zfp_type::zfp_type_none;
966 case Pack::Type::PF32: t = zfp_type::zfp_type_float;
break;
967 case Pack::Type::PF64: t = zfp_type::zfp_type_double;
break;
968 default:
XABORTM(
"cannot encode compressed type; data typ not available");
970 XASSERT(t != zfp_type::zfp_type_none);
973 std::size_t raw_size =
element_size(raw_type) * count + 1024u;
974 std::vector<char> tmp(raw_size);
980 std::size_t array_size;
981 std::size_t real_bytes;
983 field = zfp_field_alloc();
984 zfp = zfp_stream_open(NULL);
986 stream = stream_open(buf, buf_size);
988 stream_rseek(stream, 24u);
989 uint codec = (uint)stream_read_bits(stream, 8u);
991 codec == zfp_codec_version,
992 "cannot decode compressed type; zfp version not compatible \n "
993 "zfp_Systemcodec: " +
995 stream_rewind(stream);
997 zfp_stream_set_bit_stream(zfp, stream);
999 zfp_read_header(zfp, field, zfp_header_mask);
1000 array_size = zfp_field_size(field, NULL);
1002 if(t != field->type)
1003 XABORTM(
"cannot decode compressed type; given array and saved data do not "
1004 "have the same type");
1006 if(array_size - 3 > count)
1007 XABORTM(
"cannot decode compressed data; given count is too small for "
1008 "decompressed data!");
1010 field->data = tmp.data();
1012 real_bytes = zfp_decompress(zfp, field);
1015 decode_raw(dst, tmp.data(), count, raw_type, swap_bytes);
1018 zfp_field_free(field);
1019 zfp_stream_close(zfp);
1020 stream_close(stream);
1031 XABORTM(
"cannot decode compressed type; zfp not available");
1032 return std::size_t(0);
1040 static constexpr std::string_view base64_alphabet =
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
1041 static constexpr char base64_padding =
'=';
1046 return (std::isalnum(c) != 0) || c ==
'+' || c ==
'/' || c == base64_padding;
1059 chars[0] =
static_cast<Pack::u8>((quantum[0] & 0b11111100U) >> 2U);
1062 chars[1] =
static_cast<Pack::u8>(((quantum[0] & 0b00000011U) << 4U) | ((quantum[1] & 0b11110000U) >> 4U));
1065 chars[2] =
static_cast<Pack::u8>(((quantum[1] & 0b00001111U) << 2U) | ((quantum[2] & 0b11000000U) >> 6U));
1068 chars[3] =
static_cast<Pack::u8>(quantum[2] & 0b00111111U);
1082 quantum[0] =
static_cast<Pack::u8>(((chars[0] & 0b11111111U) << 2U) | ((chars[1] & 0b00110000U) >> 4U));
1085 quantum[1] =
static_cast<Pack::u8>(((chars[1] & 0b00001111U) << 4U) | ((chars[2] & 0b00111100U) >> 2U));
1088 quantum[2] =
static_cast<Pack::u8>(((chars[2] & 0b00000011U) << 6U) | (chars[3] & 0b00111111U));
1100 return std::all_of(s.begin(), s.end(), [](
char c) { return is_valid_base64_char(c); });
1131 std::array<Pack::u8, 3> quantum{};
1134 std::array<Pack::u8, 4> chars{};
1138 const auto num_bytes =
static_cast<Index>(std::distance(begin, end));
1139 const Index full_quantums = num_bytes /
Index(3);
1140 String output((full_quantums * 4) + (num_bytes % 3 == 0 ? 0 : 4),
'=');
1145 Index quantum_idx(0);
1148 Index output_pos(0);
1153 while(next_byte != end)
1155 quantum[quantum_idx++] = *next_byte++;
1158 if(quantum_idx == 3)
1164 output[output_pos++] = base64_alphabet[idx];
1176 for(
Index j = quantum_idx; j < 3; j++)
1185 for(
Index j(0); j < (quantum_idx + 1); j++)
1187 output[output_pos++] = base64_alphabet[chars[j]];
1214 std::array<Pack::u8, 3> quantum{};
1216 std::array<Pack::u8, 4> chars{};
1218 std::vector<Pack::u8> output;
1226 auto next_char = s.begin();
1228 while(next_char != s.end() &&
is_valid_base64_char(*next_char) && *next_char != base64_padding)
1231 chars[char_idx++] =
static_cast<Pack::u8>(base64_alphabet.find(*next_char++));
1239 output.push_back(
byte);
1249 for(
Index j = char_idx; j < 4; j++)
1258 for(
Index j(0); j < (char_idx - 1); j++)
1260 output.push_back(quantum[j]);
1281#if defined(FEAT_HAVE_PACK_TYPE_F16)
1287#if defined(FEAT_HAVE_PACK_TYPE_F128)
1291 template Pack::Type deduct_type<long long>();
1293 template std::size_t encode<i8>(
void*,
const i8*, std::size_t, std::size_t,
Pack::Type,
bool,
double);
1294 template std::size_t encode<i16>(
void*,
const i16*, std::size_t, std::size_t,
Pack::Type,
bool,
double);
1295 template std::size_t encode<i32>(
void*,
const i32*, std::size_t, std::size_t,
Pack::Type,
bool,
double);
1296 template std::size_t encode<i64>(
void*,
const i64*, std::size_t, std::size_t,
Pack::Type,
bool,
double);
1298 template std::size_t encode<u8>(
void*,
const u8*, std::size_t, std::size_t,
Pack::Type,
bool,
double);
1299 template std::size_t encode<u16>(
void*,
const u16*, std::size_t, std::size_t,
Pack::Type,
bool,
double);
1300 template std::size_t encode<u32>(
void*,
const u32*, std::size_t, std::size_t,
Pack::Type,
bool,
double);
1301 template std::size_t encode<u64>(
void*,
const u64*, std::size_t, std::size_t,
Pack::Type,
bool,
double);
1303#if defined(FEAT_HAVE_PACK_TYPE_F16)
1304 template std::size_t encode<f16>(
void*,
const f16*, std::size_t, std::size_t,
Pack::Type,
bool,
double);
1306 template std::size_t encode<f32>(
void*,
const f32*, std::size_t, std::size_t,
Pack::Type,
bool,
double);
1307 template std::size_t encode<f64>(
void*,
const f64*, std::size_t, std::size_t,
Pack::Type,
bool,
double);
1309#if defined(FEAT_HAVE_PACK_TYPE_F128)
1310 template std::size_t encode<f128>(
void*,
const f128*, std::size_t, std::size_t,
Pack::Type,
bool,
double);
1313 template std::size_t encode<long long>(
void*,
const long long*, std::size_t, std::size_t,
Pack::Type,
bool,
double);
1315 template std::size_t decode<i8>(
i8*,
void*, std::size_t, std::size_t,
Pack::Type,
bool);
1316 template std::size_t decode<i16>(
i16*,
void*, std::size_t, std::size_t,
Pack::Type,
bool);
1317 template std::size_t decode<i32>(
i32*,
void*, std::size_t, std::size_t,
Pack::Type,
bool);
1318 template std::size_t decode<i64>(
i64*,
void*, std::size_t, std::size_t,
Pack::Type,
bool);
1320 template std::size_t decode<u8>(
u8*,
void*, std::size_t, std::size_t,
Pack::Type,
bool);
1321 template std::size_t decode<u16>(
u16*,
void*, std::size_t, std::size_t,
Pack::Type,
bool);
1322 template std::size_t decode<u32>(
u32*,
void*, std::size_t, std::size_t,
Pack::Type,
bool);
1323 template std::size_t decode<u64>(
u64*,
void*, std::size_t, std::size_t,
Pack::Type,
bool);
1325#if defined(FEAT_HAVE_PACK_TYPE_F16)
1326 template std::size_t decode<f16>(
f16*,
void*, std::size_t, std::size_t,
Pack::Type,
bool);
1328 template std::size_t decode<f32>(
f32*,
void*, std::size_t, std::size_t,
Pack::Type,
bool);
1329 template std::size_t decode<f64>(
f64*,
void*, std::size_t, std::size_t,
Pack::Type,
bool);
1331#if defined(FEAT_HAVE_PACK_TYPE_F128)
1332 template std::size_t decode<f128>(f128*,
void*, std::size_t, std::size_t,
Pack::Type,
bool);
1335 template std::size_t decode<long long>(
long long*,
void*, std::size_t, std::size_t,
Pack::Type,
bool);
1338 template Pack::Type deduct_type<unsigned long>();
1339 template std::size_t encode<unsigned long>(
void*,
const unsigned long*, std::size_t, std::size_t,
Pack::Type,
bool,
double);
1340 template std::size_t decode<unsigned long>(
unsigned long*,
void*, std::size_t, std::size_t,
Pack::Type,
bool);
#define XABORTM(msg)
Abortion macro definition with custom message.
#define XASSERT(expr)
Assertion macro definition.
#define XASSERTM(expr, msg)
Assertion macro definition with custom message.
String class implementation.
Tag class for floating data types.
Tag class for integral data types.
Data Array Pack namespace.
static std::size_t xdecode(T_ *dest, const void *buf, const std::size_t count, bool swap_bytes)
Encodes an array by converting each of its elements to a desired type.
static std::size_t lossy_estimate_size(const std::size_t count, const Pack::Type type, const double tolerance)
Computes the estimated (upper bound) pack buffer size for an array for lossy compression.
std::int32_t i32
32-bit signed integer type
std::size_t encode(void *buf, const T_ *src, const std::size_t buf_size, const std::size_t count, const Pack::Type pack_type, bool swap_bytes, double tolerance)
Encodes an array into a packed buffer.
std::uint64_t u64
64-bit unsigned integer type
static std::size_t lossless_encode(void *buf, const T_ *src, const std::size_t buf_size, const std::size_t count, const Pack::Type pack_type, bool swap_bytes)
Encodes an array into a packed buffer.
std::size_t element_size(const Pack::Type type)
Returns the size of a Pack::Type element in bytes.
std::size_t estimate_size(const std::size_t count, const Pack::Type type, const double tolerance)
Computes the estimated (upper bound) pack buffer size for an array.
static std::size_t lossless_decode(T_ *dst, const void *buf, const std::size_t count, const std::size_t buf_size, const Pack::Type pack_type, bool swap_bytes)
Decodes an array from a packed buffer.
String base64_encode(const Pack::u8 *begin, const Pack::u8 *end)
Encodes bytes into a Base64 string.
static void decode_base64_quantum(std::array< Pack::u8, 3 > &quantum, const std::array< Pack::u8, 4 > &chars)
Decodes a group of four Base64 characters into a group of three bytes.
static std::size_t decode_raw(T_ *dst, const void *buf, const std::size_t count, const Pack::Type pack_type, bool swap_bytes)
Decodes an array from a packed buffer without compression support.
static bool is_valid_base64_char(const char c)
Checks if the given characters is a valid Base64 character.
Half f16
16-bit floating point type
float f32
32-bit floating point type
static void encode_base64_quantum(const std::array< Pack::u8, 3 > &quantum, std::array< Pack::u8, 4 > &chars)
Encodes a group of three bytes into four Base64 characters.
std::int16_t i16
16-bit signed integer type
std::uint32_t u32
32-bit unsigned integer type
std::int64_t i64
64-bit signed integer type
std::uint16_t u16
16-bit unsigned integer type
static std::size_t lossy_decode(T_ *dst, void *buf, const std::size_t count, const std::size_t buf_size, const Pack::Type pack_type, bool swap_bytes)
Decodes an array from a packed buffer with lossy saved compression data.
static std::size_t encode_raw(void *buf, const T_ *src, const std::size_t count, const Pack::Type pack_type, bool swap_bytes)
Encodes an array into a packed buffer without compression support.
std::int8_t i8
8-bit signed integer type
static std::size_t lossy_encode(void *buf, T_ *src, const std::size_t buf_size, const std::size_t count, const Pack::Type pack_type, bool swap_bytes, const double tolerance)
Encodes an array into a packed buffer.
double f64
64-bit floating point type
std::size_t decode(T_ *dst, void *buf, const std::size_t count, const std::size_t buf_size, const Pack::Type pack_type, bool swap_bytes)
Decodes an array from a packed buffer.
std::uint8_t u8
8-bit unsigned integer type
Pack::Type deduct_type()
Deduct the (raw) Pack::Type from a given data type T_.
bool is_valid_base64_string(const String &s)
std::vector< Pack::u8 > base64_decode(const String &s)
Decodes a Base64 string into bytes.
X_ xswap(X_ x)
Swaps the bytes of an object.
static std::size_t xencode(void *buf, const T_ *src, const std::size_t count, bool swap_bytes)
bitmask for zfp header
String stringify(const T_ &item)
Converts an item into a String.
std::uint64_t Index
Index data type.
auxiliary helper class: swaps the bytes of an 8/16/32/64/128 byte type