summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Userland/Libraries/LibCore/Stream.h14
1 files changed, 14 insertions, 0 deletions
diff --git a/Userland/Libraries/LibCore/Stream.h b/Userland/Libraries/LibCore/Stream.h
index 7e3cf6f23a..1351a41a8a 100644
--- a/Userland/Libraries/LibCore/Stream.h
+++ b/Userland/Libraries/LibCore/Stream.h
@@ -102,6 +102,13 @@ public:
virtual ErrorOr<void> write_entire_buffer(ReadonlyBytes);
template<typename T>
+ requires(requires(Stream& stream) { { T::read_from_stream(stream) } -> SameAs<ErrorOr<T>>; })
+ ErrorOr<T> read_value()
+ {
+ return T::read_from_stream(*this);
+ }
+
+ template<typename T>
requires(Traits<T>::is_trivially_serializable())
ErrorOr<T> read_value()
{
@@ -111,6 +118,13 @@ public:
}
template<typename T>
+ requires(requires(T t, Stream& stream) { { t.write_to_stream(stream) } -> SameAs<ErrorOr<void>>; })
+ ErrorOr<void> write_value(T const& value)
+ {
+ return value.write_to_stream(*this);
+ }
+
+ template<typename T>
requires(Traits<T>::is_trivially_serializable())
ErrorOr<void> write_value(T const& value)
{