39 lines
720 B
C++
39 lines
720 B
C++
#pragma once
|
|
|
|
/** data source wrapping the memory */
|
|
template <typename File> 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 <typename T> void readType(T& dst) {
|
|
read(sizeof(T), &dst);
|
|
}
|
|
|
|
/** read x bytes from the input into dst */
|
|
template <typename T> void read(uint32_t size, T* dst) {
|
|
memcpy(dst, &src[pos], size);
|
|
pos += size;
|
|
}
|
|
|
|
};
|