added code for mp3 and jpeg parsing
added interface for data sources
This commit is contained in:
38
data/formats/DataSourceMemory.h
Normal file
38
data/formats/DataSourceMemory.h
Normal 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;
|
||||
}
|
||||
|
||||
};
|
||||
Reference in New Issue
Block a user