diff options
author | Timothy Flynn <trflynn89@pm.me> | 2022-11-15 11:24:59 -0500 |
---|---|---|
committer | Tim Flynn <trflynn89@pm.me> | 2022-11-15 13:25:51 -0500 |
commit | 05f41382bb527fbf2bb47340ad065b36f2e7409f (patch) | |
tree | 3da51238f398d92fc289351837cd26699bdad21f /Userland/Libraries/LibIPC | |
parent | b1ea418d14b4392741720914b834c61322cdb5b4 (diff) | |
download | serenity-05f41382bb527fbf2bb47340ad065b36f2e7409f.zip |
Userland: Properly define IPC::encode and IPC::decode specializations
In order to avoid the base encode/decode methods from being used (and
failing a static assertion), we must be sure to declare/define the
custom type implementations as template specializations.
After this, LibIPC is no longer sensitive to include order.
Diffstat (limited to 'Userland/Libraries/LibIPC')
-rw-r--r-- | Userland/Libraries/LibIPC/Decoder.cpp | 3 | ||||
-rw-r--r-- | Userland/Libraries/LibIPC/Encoder.cpp | 3 |
2 files changed, 6 insertions, 0 deletions
diff --git a/Userland/Libraries/LibIPC/Decoder.cpp b/Userland/Libraries/LibIPC/Decoder.cpp index 8e2f25b4e6..2cb9daac03 100644 --- a/Userland/Libraries/LibIPC/Decoder.cpp +++ b/Userland/Libraries/LibIPC/Decoder.cpp @@ -170,6 +170,7 @@ ErrorOr<void> Decoder::decode([[maybe_unused]] File& file) return {}; } +template<> ErrorOr<void> decode(Decoder& decoder, Core::AnonymousBuffer& buffer) { bool valid; @@ -187,6 +188,7 @@ ErrorOr<void> decode(Decoder& decoder, Core::AnonymousBuffer& buffer) return {}; } +template<> ErrorOr<void> decode(Decoder& decoder, Core::DateTime& datetime) { i64 timestamp; @@ -195,6 +197,7 @@ ErrorOr<void> decode(Decoder& decoder, Core::DateTime& datetime) return {}; } +template<> ErrorOr<void> decode(Decoder& decoder, Core::ProxyData& data) { UnderlyingType<decltype(data.type)> type; diff --git a/Userland/Libraries/LibIPC/Encoder.cpp b/Userland/Libraries/LibIPC/Encoder.cpp index 132cc8adaa..a8e86f16bf 100644 --- a/Userland/Libraries/LibIPC/Encoder.cpp +++ b/Userland/Libraries/LibIPC/Encoder.cpp @@ -196,6 +196,7 @@ Encoder& Encoder::operator<<(File const& file) return *this; } +template<> bool encode(Encoder& encoder, Core::AnonymousBuffer const& buffer) { encoder << buffer.is_valid(); @@ -206,12 +207,14 @@ bool encode(Encoder& encoder, Core::AnonymousBuffer const& buffer) return true; } +template<> bool encode(Encoder& encoder, Core::DateTime const& datetime) { encoder << static_cast<i64>(datetime.timestamp()); return true; } +template<> bool encode(Encoder& encoder, Core::ProxyData const& proxy) { encoder << to_underlying(proxy.type); |