summaryrefslogtreecommitdiff
path: root/Libraries/LibIPC/Decoder.h
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2020-05-12 19:02:44 +0200
committerAndreas Kling <kling@serenityos.org>2020-05-12 19:04:05 +0200
commit413ab652c88a9a5ee025d67ab097e047235b9d09 (patch)
treebd3a934cf1a55f901f5d4ced33ba4fa5466a71ad /Libraries/LibIPC/Decoder.h
parent6800f6eff5f1e6e8c463163ba532204c2099f8ff (diff)
downloadserenity-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.h17
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;
};