diff options
author | Stanislaw Halik <sthalik@misaki.pl> | 2022-10-28 22:10:27 +0200 |
---|---|---|
committer | Stanislaw Halik <sthalik@misaki.pl> | 2022-10-28 22:10:27 +0200 |
commit | 280b4c235fe11dd629f882f0fb5054384fcee1d7 (patch) | |
tree | e89735003b52b04e3c17a3ad5532b36e055cdda7 /serialize/binary-reader.inl | |
parent | 1b84fc144f77c4ebef6fdc0a476410420e0a95b3 (diff) |
more work
Diffstat (limited to 'serialize/binary-reader.inl')
-rw-r--r-- | serialize/binary-reader.inl | 15 |
1 files changed, 12 insertions, 3 deletions
diff --git a/serialize/binary-reader.inl b/serialize/binary-reader.inl index cf935a76..ad2d59bc 100644 --- a/serialize/binary-reader.inl +++ b/serialize/binary-reader.inl @@ -33,7 +33,7 @@ template<typename T> T binary_reader<It>::read() noexcept
{
value_u buf = read_u<T>();
- return *reinterpret_cast<T>(buf.bytes);
+ return *reinterpret_cast<T*>(buf.bytes);
}
template<string_input_iterator It>
@@ -79,9 +79,18 @@ constexpr value_u binary_reader<It>::read_u() noexcept template<string_input_iterator It, serializable T>
binary_reader<It>& operator>>(binary_reader<It>& reader, T& x) noexcept
{
- value_u u = reader.template read<T>();
- x = *reinterpret_cast<T*>(&u.bytes[0]);
+ x = reader.template read<T>();
return reader;
}
+template<string_input_iterator It>
+constexpr StringView binary_reader<It>::read_asciiz_string() noexcept
+{
+ const It pos = it;
+ while (it != end)
+ if (char c = *it++; c == '\0')
+ return StringView{pos, (std::size_t)std::distance(pos, end), StringViewFlag::NullTerminated};
+ fm_abort("unexpected EOF while reading a string");
+}
+
} // namespace floormat::Serialize
|