From fcdca58617caf6a8c034a91588d6abb399be6b57 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Tue, 18 May 2021 00:06:37 +0100 Subject: Initial commit, still lots to do! --- lib/rawDataReader.cpp | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 lib/rawDataReader.cpp (limited to 'lib/rawDataReader.cpp') diff --git a/lib/rawDataReader.cpp b/lib/rawDataReader.cpp new file mode 100644 index 0000000..2dd87a9 --- /dev/null +++ b/lib/rawDataReader.cpp @@ -0,0 +1,47 @@ +#include "rawDataReader.h" +#include "helpers.h" +#include "streamSupport.h" +#include +#include +#include + +namespace MyGrate { + RawDataReader::RawDataReader(const void * const d, std::size_t l) : + rawdata {static_cast(d)}, len {l} + { + } + + RawDataReader::RawDataReader(const MARIADB_STRING & str) : RawDataReader {str.str, str.length} { } + + void + RawDataReader::offsetSizeCheck(size_t l) const + { + if (offset + l > len) { + throw std::range_error("Read beyond end of data"); + } + } + + void + RawDataReader::discard(size_t d) + { + offset += d; + } + + template<> + uint64_t + RawDataReader::readValue() + { + switch (const auto byte1 {readValue()}) { + case 0 ... 250: // The value as-is + return byte1; + case 252: // 2 bytes + return readValue(); + case 253: // 3 bytes + return readValue(); + case 254: // 8 bytes + return readValue(); + default:; + } + throw std::domain_error("Invalid first byte of packed integer"); + } +} -- cgit v1.2.3