#ifndef MYGRATE_RAW_DATA_READER_H #define MYGRATE_RAW_DATA_READER_H #include "helpers.h" #include #include #include #include #include #include // IWYU pragma: keep #include #include #include #include namespace MyGrate { struct PackedInteger { }; template struct type_map { using target = T; }; template<> struct type_map { using target = uint64_t; }; class RawDataReader { public: explicit RawDataReader(const void * const d, std::size_t len); explicit RawDataReader(const MARIADB_STRING & str); template typename type_map::target readValue() { static_assert(L > 0 && L <= sizeof(T), "Read exceeds target size"); return readValue(L); } template typename type_map::target readValue(size_t L) { verify(L > 0 && L <= sizeof(T), "Read exceeds target size"); offsetSizeCheck(L); T v {}; memcpy(&v, rawdata + offset, L); offset += L; return v; } template T viewValue(size_t L) { static_assert(sizeof(typename T::value_type) == sizeof(std::byte)); offsetSizeCheck(L); T v {reinterpret_cast(rawdata + offset), L}; offset += L; return v; } void discard(size_t); private: void offsetSizeCheck(size_t) const; const std::byte * const rawdata; const std::size_t len; std::size_t offset {0}; }; template<> uint64_t RawDataReader::readValue(); } #endif