File tree Expand file tree Collapse file tree 1 file changed +16
-0
lines changed
Userland/Libraries/LibCore Expand file tree Collapse file tree 1 file changed +16
-0
lines changed Original file line number Diff line number Diff line change @@ -108,6 +108,22 @@ class Stream {
108
108
return !write_entire_buffer (buffer).is_error ();
109
109
}
110
110
111
+ template <typename T>
112
+ requires (IsTriviallyDestructible<T>)
113
+ ErrorOr<T> read_trivial_value ()
114
+ {
115
+ alignas (T) u8 buffer[sizeof (T)] = {};
116
+ TRY (read_entire_buffer (buffer));
117
+ return *bit_cast<T>(buffer);
118
+ }
119
+
120
+ template <typename T>
121
+ requires (IsTriviallyDestructible<T>)
122
+ ErrorOr<void > write_trivial_value (T const & value)
123
+ {
124
+ return write_entire_buffer ({ &value, sizeof (value) });
125
+ }
126
+
111
127
// / Returns whether the stream has reached the end of file. For sockets,
112
128
// / this most likely means that the protocol has disconnected (in the case
113
129
// / of TCP). For seekable streams, this means the end of the file. Note that
You can’t perform that action at this time.
0 commit comments