45 lines
906 B
C++
45 lines
906 B
C++
#include <base/io/Stream.hpp>
|
|
#include <base/Types.hpp>
|
|
#include <dmbmx/ZiffChunk.hpp>
|
|
#include <functional>
|
|
|
|
#include "base/FourCC.hpp"
|
|
|
|
namespace dmtools::dmbmx {
|
|
|
|
/// A input stream that reads a ZIFF stream and posts chunks.
|
|
struct ZiffInputStream {
|
|
/// A ZIFF chunk.
|
|
struct Chunk {
|
|
ZiffChunkHeader chunkHeader;
|
|
std::vector<u8> chunkData;
|
|
|
|
/// Casts the data to some other type.
|
|
template <class T>
|
|
T* As() {
|
|
return std::bit_cast<T*>(chunkData.data());
|
|
}
|
|
};
|
|
|
|
using ChunkCallback = std::function<void(Chunk&)>;
|
|
|
|
explicit ZiffInputStream(io::Stream& stream, FourCCT expectedFormCkId);
|
|
|
|
void SetChunkCallback(ChunkCallback&& chunkCallback);
|
|
|
|
void Process();
|
|
|
|
void Rewind();
|
|
|
|
private:
|
|
|
|
bool NextChunkImpl(bool isForm);
|
|
|
|
io::Stream& stream;
|
|
FourCCT expectedFormCkId {};
|
|
Chunk currentChunk {};
|
|
ChunkCallback callback {};
|
|
};
|
|
|
|
} // namespace dmtools::dmbmx
|