Squashed 'deps/nostalgia/' changes from b97d7d99..04f3d6b4

04f3d6b4 [keel] Fix some static const vars to be constexpr
db2dc28f [keel] Remove use of removed ModelValue operator
74fb051e [ox] Remove panicing ModelValue operators
24fda7d5 [ox] Make serialize and allocate Writer_c functions take refs
a60cdf0a Merge commit '9c712cc38ae706b021807b271899bce56c234fa5'
9a0a2fd4 Merge commit '56f9d7a4634c9de9b09df390c4385c67ab646607'
9c0acf1b Merge commit 'ace68f7c1d870ed53e69c55ba53709a9425388be'
a41e93c5 Merge commit '8e0467ca5fdb3f983738a97c17cba742a0d233fd'
dbcd37d7 Merge commit '0d61e5a064382a7076b62d32b25c70298ee0706e'
6a500345 Merge commit '057272347486efe5046691f32f51604e3a594e6a'
f038b89a Merge commit 'cfc27a384b00388fc1ce30ac47c266ddd1f8e6f1'
b9fddd47 Merge commit 'db978290f3465d2da30a27a98b12face50bbe091'
961ab756 Merge commit 'ae1f8ce11a81624f376be3a3dd56e80ba479dd89'
d740609c Merge commit '6640e00ad9ee5b731a2ddb06da31436463c3ae65'
08be822b [ox/fs] Add FileAddress::operator==(FileAddress)

git-subtree-dir: deps/nostalgia
git-subtree-split: 04f3d6b491105a4f124d9738f612b9e0c505b2b0
This commit is contained in:
2024-03-14 23:33:20 -05:00
parent 9c712cc38a
commit d6403991d4
8 changed files with 66 additions and 84 deletions

View File

@@ -78,19 +78,4 @@ class FileReader: public Reader_v {
};
#endif
/**
* Allocates the specified amount of data at the end of the current read stream.
* @param reader
* @param sz
* @return
*/
constexpr ox::Result<std::size_t> allocate(Reader_c auto *reader, std::size_t sz) noexcept {
const auto p = reader->tellg();
oxReturnError(reader->seekg(0, ios_base::end));
const auto out = reader->tellg();
oxReturnError(reader->read(nullptr, sz));
oxReturnError(reader->seekg(p));
return out;
}
}

View File

@@ -54,42 +54,42 @@ constexpr auto alignOf(const VectorMemMap<PlatSpec>&) noexcept {
}
template<typename PlatSpec, typename T>
constexpr ox::Error pad(Writer_c auto *w, const T *v) noexcept {
constexpr ox::Error pad(Writer_c auto &w, const T *v) noexcept {
const auto a = PlatSpec::alignOf(*v);
const auto excess = w->tellp() % a;
const auto excess = w.tellp() % a;
if (excess) {
return w->write(nullptr, a - excess);
return w.write(nullptr, a - excess);
} else {
return {};
}
}
template<typename PlatSpec>
constexpr ox::Error serialize(Writer_c auto *buff, const VectorMemMap<PlatSpec> &vm) noexcept {
oxReturnError(buff->write(nullptr, vm.smallVecSize));
oxReturnError(serialize(buff, PlatSpec::correctEndianness(vm.allocator)));
oxReturnError(pad<PlatSpec>(buff, &vm.size));
oxReturnError(serialize(buff, PlatSpec::correctEndianness(vm.size)));
oxReturnError(serialize(buff, PlatSpec::correctEndianness(vm.cap)));
oxReturnError(serialize(buff, PlatSpec::correctEndianness(vm.items)));
constexpr ox::Error serialize(Writer_c auto &w, const VectorMemMap<PlatSpec> &vm) noexcept {
oxReturnError(w.write(nullptr, vm.smallVecSize));
oxReturnError(serialize(w, PlatSpec::correctEndianness(vm.allocator)));
oxReturnError(pad<PlatSpec>(w, &vm.size));
oxReturnError(serialize(w, PlatSpec::correctEndianness(vm.size)));
oxReturnError(serialize(w, PlatSpec::correctEndianness(vm.cap)));
oxReturnError(serialize(w, PlatSpec::correctEndianness(vm.items)));
return {};
}
template<typename T>
constexpr ox::Error serialize(Writer_c auto *buff, T val) noexcept requires(is_integer_v<T>) {
constexpr ox::Error serialize(Writer_c auto &w, T val) noexcept requires(is_integer_v<T>) {
ox::Array<char, sizeof(T)> tmp;
for (auto i = 0u; i < sizeof(T); ++i) {
tmp[i] = static_cast<char>((val >> i * 8) & 255);
}
return buff->write(tmp.data(), tmp.size());
return w.write(tmp.data(), tmp.size());
};
template<typename T>
constexpr ox::Result<ox::Array<char, sizeof(T)>> serialize(const T &in) noexcept {
ox::Array<char, sizeof(T)> out = {};
CharBuffWriter w(out);
oxReturnError(serialize(&w, in));
oxReturnError(serialize(w, in));
return out;
};
}
}

View File

@@ -72,12 +72,12 @@ class WriterT: public Writer_v {
* @param sz
* @return
*/
constexpr ox::Result<std::size_t> allocate(Writer_c auto *writer, std::size_t sz) noexcept {
const auto p = writer->tellp();
oxReturnError(writer->seekp(0, ios_base::end));
const auto out = writer->tellp();
oxReturnError(writer->write(nullptr, sz));
oxReturnError(writer->seekp(p));
constexpr ox::Result<std::size_t> allocate(Writer_c auto &writer, std::size_t sz) noexcept {
const auto p = writer.tellp();
oxReturnError(writer.seekp(0, ios_base::end));
const auto out = writer.tellp();
oxReturnError(writer.write(nullptr, sz));
oxReturnError(writer.seekp(p));
return out;
}