diff --git a/deps/ox/src/ox/std/serialize.hpp b/deps/ox/src/ox/std/serialize.hpp index 94cd77cd..4a5dd912 100644 --- a/deps/ox/src/ox/std/serialize.hpp +++ b/deps/ox/src/ox/std/serialize.hpp @@ -34,8 +34,10 @@ constexpr auto sizeOf(const VectorMemMap *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&) noexcept { return PlatSpec::alignOf(i); } +template +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 constexpr ox::Error serialize(Writer_c auto *buff, const VectorMemMap &vm) noexcept { oxReturnError(buff->write(nullptr, vm.smallVecSize)); oxReturnError(serialize(buff, PlatSpec::correctEndianness(vm.allocator))); + oxReturnError(pad(buff, &vm.size)); oxReturnError(serialize(buff, PlatSpec::correctEndianness(vm.size))); oxReturnError(serialize(buff, PlatSpec::correctEndianness(vm.cap))); oxReturnError(serialize(buff, PlatSpec::correctEndianness(vm.items)));