Files
ESP8266lib/data/formats/DataSourceMemory.h
kazu 331f9f3e6c added code for mp3 and jpeg parsing
added interface for data sources
2021-02-28 20:46:38 +01:00

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;
}
};