#include
#include
namespace dmtools::io {
MemoryStream::MemoryStream(u8* memory, usize size) {
beg = memory;
cur = beg;
end = memory + size;
this->size = size;
}
MemoryStream::~MemoryStream() {
}
StreamDiff MemoryStream::ReadSome(u8* buffer, usize length) {
if(Eof())
return -1;
memcpy(&buffer[0], cur, length);
cur += length;
return length;
}
StreamDiff MemoryStream::WriteSome(const u8* buffer, usize length) {
return -1;
};
StreamDiff MemoryStream::Seek(StreamDiff where, StreamSeekDirection dir) {
using enum StreamSeekDirection;
auto last = Tell();
switch(dir) {
case Beg:
cur = beg + where;
break;
case Cur:
cur += where;
break;
case End: // TODO
cur = end;
break;
}
return last;
}
StreamDiff MemoryStream::Tell() const {
return (cur - beg);
}
bool MemoryStream::Ok() const {
return !Eof();
}
bool MemoryStream::Eof() const {
return cur == end;
};
} // namespace dmtools::io