#pragma once #include "binary-writer.hpp" #include "binary-serializer.hpp" #include "compat/assert.hpp" #include #include namespace floormat::Serialize { template It> constexpr binary_writer::binary_writer(It it) noexcept : it{it}, _bytes_written{0} {} template It> template constexpr void binary_writer::write(T x) noexcept { _bytes_written += sizeof(T); constexpr size_t N = sizeof(T); const auto buf = std::bit_cast, T>(maybe_byteswap(x)); for (auto i = 0uz; i < N; i++) *it++ = buf[i]; } template It, serializable T> constexpr binary_writer& operator<<(binary_writer& writer, T x) noexcept { writer.template write(x); return writer; } template It> constexpr void binary_writer::write_asciiz_string(StringView str) noexcept { //fm_debug_assert(str.flags() & StringViewFlag::NullTerminated); fm_debug_assert(!str.find('\0')); const auto sz = str.size(); _bytes_written += sz + 1; for (auto i = 0uz; i < sz; i++) *it++ = str[i]; *it++ = '\0'; } } // namespace floormat::Serialize