#pragma once /** data source wrapping the memory */ template class DataSourceMemory { const uint8_t* src; const uint32_t len; uint32_t pos; public: /** ctor with the memory region */ DataSourceMemory(const uint8_t* src, const uint32_t len) : src(src), len(len) { } /** get the current position */ uint32_t curPos() const { return pos; } /** seek to the given position */ void seekTo(uint32_t newPos) { pos = newPos; } /** read an entity */ template void readType(T& dst) { read(sizeof(T), &dst); } /** read x bytes from the input into dst */ template void read(uint32_t size, T* dst) { memcpy(dst, &src[pos], size); pos += size; } };