added code for mp3 and jpeg parsing

added interface for data sources
This commit is contained in:
2021-02-28 20:46:38 +01:00
parent 422610c21c
commit 331f9f3e6c
11 changed files with 5912 additions and 0 deletions

View File

@@ -0,0 +1,38 @@
#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;
}
};