diff options
author | Andreas Kling <kling@serenityos.org> | 2020-05-12 19:02:44 +0200 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2020-05-12 19:04:05 +0200 |
commit | 413ab652c88a9a5ee025d67ab097e047235b9d09 (patch) | |
tree | bd3a934cf1a55f901f5d4ced33ba4fa5466a71ad /Libraries/LibIPC/Decoder.h | |
parent | 6800f6eff5f1e6e8c463163ba532204c2099f8ff (diff) | |
download | serenity-413ab652c88a9a5ee025d67ab097e047235b9d09.zip |
LibIPC+IPCCompiler: Templatize encoding/decoding of Optional<T>
This was the last one! IPCCompiler no longer has any type-specific
encoding/decoding logic! :^)
Diffstat (limited to 'Libraries/LibIPC/Decoder.h')
-rw-r--r-- | Libraries/LibIPC/Decoder.h | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/Libraries/LibIPC/Decoder.h b/Libraries/LibIPC/Decoder.h index d79abb9c06..340a86701f 100644 --- a/Libraries/LibIPC/Decoder.h +++ b/Libraries/LibIPC/Decoder.h @@ -83,6 +83,23 @@ public: return true; } + template<typename T> + bool decode(Optional<T>& optional) + { + bool has_value; + if (!decode(has_value)) + return false; + if (!has_value) { + optional = {}; + return true; + } + T value; + if (!decode(value)) + return false; + optional = move(value); + return true; + } + private: BufferStream& m_stream; }; |