[ox/std] Fix VectorMemMap sizeOf
This commit is contained in:
parent
a946f8dae1
commit
86c33019fe
16
deps/ox/src/ox/std/serialize.hpp
vendored
16
deps/ox/src/ox/std/serialize.hpp
vendored
@ -34,8 +34,10 @@ constexpr auto sizeOf(const VectorMemMap<PlatSpec> *t) noexcept {
|
||||
std::size_t size = 0;
|
||||
if (t->smallVecSize) {
|
||||
size += t->smallVecSize;
|
||||
size += padding(size, PlatSpec::alignOf(t->size));
|
||||
size += padding(size, PlatSpec::alignOf(t->allocator));
|
||||
}
|
||||
size += sizeof(t->allocator);
|
||||
size += padding(size, PlatSpec::alignOf(t->size));
|
||||
size += sizeof(t->size);
|
||||
size += padding(size, PlatSpec::alignOf(t->cap));
|
||||
size += sizeof(t->cap);
|
||||
@ -51,10 +53,22 @@ constexpr auto alignOf(const VectorMemMap<PlatSpec>&) noexcept {
|
||||
return PlatSpec::alignOf(i);
|
||||
}
|
||||
|
||||
template<typename PlatSpec, typename T>
|
||||
constexpr ox::Error pad(Writer_c auto *w, const T *v) noexcept {
|
||||
const auto a = PlatSpec::alignOf(*v);
|
||||
const auto excess = w->tellp() % a;
|
||||
if (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)));
|
||||
|
Loading…
Reference in New Issue
Block a user