From 5e1698a3213a330de976bbed6d96b89a551a395c Mon Sep 17 00:00:00 2001 From: Gary Talent Date: Tue, 27 Jan 2026 23:15:53 -0600 Subject: [PATCH] [ox/std] Cleanup serialize code --- deps/ox/src/ox/std/serialize.hpp | 37 ++++++++++++++++---------------- 1 file changed, 18 insertions(+), 19 deletions(-) diff --git a/deps/ox/src/ox/std/serialize.hpp b/deps/ox/src/ox/std/serialize.hpp index adc30d07..85b96210 100644 --- a/deps/ox/src/ox/std/serialize.hpp +++ b/deps/ox/src/ox/std/serialize.hpp @@ -18,7 +18,7 @@ namespace ox { template struct VectorMemMap { - const std::size_t smallVecSize = 0; // not a map value + size_t const smallVecSize = 0; // not a map value typename PlatSpec::size_t size = 0; typename PlatSpec::size_t cap = 0; typename PlatSpec::PtrType items = 0; @@ -26,11 +26,11 @@ struct VectorMemMap { template [[nodiscard]] -constexpr auto sizeOf(const VectorMemMap *t) noexcept { - constexpr auto padding = [](std::size_t size, std::size_t al) { +constexpr auto sizeOf(VectorMemMap const *t) noexcept { + constexpr auto padding = [](size_t const size, size_t const al) { return size % al; }; - std::size_t size = 0; + size_t size = 0; if (t->smallVecSize) { size += t->smallVecSize; size += padding(size, PlatSpec::alignOf(t->size)); @@ -43,17 +43,17 @@ constexpr auto sizeOf(const VectorMemMap *t) noexcept { return size; } -template +template [[nodiscard]] -constexpr auto alignOf(const VectorMemMap&) noexcept { - const typename PlatSpec::size_t i = 0; +constexpr auto alignOf(VectorMemMap const&) noexcept { + typename PlatSpec::size_t const i = 0; 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; +constexpr Error pad(Writer_c auto &w, T const *v) noexcept { + auto const a = PlatSpec::alignOf(*v); + auto const excess = w.tellp() % a; if (excess) { return w.write(nullptr, a - excess); } else { @@ -62,7 +62,7 @@ constexpr ox::Error pad(Writer_c auto &w, const T *v) noexcept { } template -constexpr ox::Error serialize(Writer_c auto &w, const VectorMemMap &vm) noexcept { +constexpr Error serialize(Writer_c auto &w, VectorMemMap const &vm) noexcept { OX_RETURN_ERROR(w.write(nullptr, vm.smallVecSize)); OX_RETURN_ERROR(serialize(w, PlatSpec::correctEndianness(vm.size))); OX_RETURN_ERROR(serialize(w, PlatSpec::correctEndianness(vm.cap))); @@ -70,21 +70,20 @@ constexpr ox::Error serialize(Writer_c auto &w, const VectorMemMap &vm return {}; } -template -constexpr ox::Error serialize(Writer_c auto &w, T val) noexcept requires(is_integral_v) { - ox::Array tmp; - for (auto i = 0u; i < sizeof(T); ++i) { +constexpr Error serialize(Writer_c auto &w, Integral_c auto val) noexcept { + Array tmp; + for (auto i = 0u; i < sizeof(val); ++i) { tmp[i] = static_cast((val >> i * 8) & 255); } return w.write(tmp.data(), tmp.size()); -}; +} template -constexpr ox::Result> serialize(const T &in) noexcept { - ox::Array out = {}; +constexpr Result> serialize(T const &in) noexcept { + Array out = {}; CharBuffWriter w(out); OX_RETURN_ERROR(serialize(w, in)); return out; -}; +} }