refactor file2 and add span with ownership

This commit is contained in:
2024-05-26 21:32:44 +02:00
parent 2420af464f
commit f2f001b190
7 changed files with 72 additions and 14 deletions

View File

@@ -25,8 +25,8 @@ bool File2MemW::write(const ByteSpan data, int64_t pos) {
return isGood();
}
std::variant<ByteSpan, std::vector<uint8_t>> File2MemW::read(uint64_t size, int64_t pos) {
return {};
ByteSpanWithOwnership File2MemW::read(uint64_t size, int64_t pos) {
return ByteSpan{};
}
File2MemR::File2MemR(ByteSpan mem) : File2I(false, true), _mem(mem) {
@@ -44,9 +44,9 @@ bool File2MemR::write(const ByteSpan data, int64_t pos) {
return false;
}
std::variant<ByteSpan, std::vector<uint8_t>> File2MemR::read(uint64_t size, int64_t pos) {
ByteSpanWithOwnership File2MemR::read(uint64_t size, int64_t pos) {
if (_read_pos >= _mem.size) {
return {};
return ByteSpan{};
}
ByteSpan ret {
@@ -54,6 +54,7 @@ std::variant<ByteSpan, std::vector<uint8_t>> File2MemR::read(uint64_t size, int6
std::min(size, _mem.size - _read_pos)
};
_read_pos += ret.size;
// return non-owning
return ret;
}