| 112 | |
| 113 | template <typename T> |
| 114 | void serialize(Writer& os, T v) { |
| 115 | if constexpr (std::is_arithmetic_v<T>) { |
| 116 | if (is_big_endian()) { |
| 117 | reverse_bytes(v); |
| 118 | } |
| 119 | os.write(reinterpret_cast<const char*>(&v), sizeof(T)); |
| 120 | } else if constexpr (std::is_enum_v<T>) { |
| 121 | serialize(os, static_cast<int>(v)); |
| 122 | } else if constexpr (std::is_same_v<T, std::nullptr_t>) { |
| 123 | } else if constexpr (is_iterable<T>) { |
| 124 | serialize(os, static_cast<uint64_t>(v.size())); |
| 125 | for (const auto& t : v) { |
| 126 | serialize(os, t); |
| 127 | } |
| 128 | } else if constexpr (is_pair<T> || is_tuple<T>) { |
| 129 | std::apply([&os](auto&... x) { (..., serialize(os, x)); }, v); |
| 130 | } else if constexpr (is_variant<T>) { |
| 131 | serialize_variant(os, v); |
| 132 | } else if constexpr (is_optional<T>) { |
| 133 | serialize(os, v.has_value()); |
| 134 | if (v.has_value()) { |
| 135 | serialize(os, *v); |
| 136 | } |
| 137 | } else { |
| 138 | NotSerializable<T>(); |
| 139 | } |
| 140 | } |
| 141 | |
| 142 | template <typename T, std::size_t... I> |
| 143 | decltype(auto) deserialize_tuple(Reader& is, std::index_sequence<I...>); |
no test coverage detected