diff options
author | Timothy Flynn <trflynn89@pm.me> | 2023-02-24 13:51:37 -0500 |
---|---|---|
committer | Tim Flynn <trflynn89@pm.me> | 2023-02-24 15:50:42 -0500 |
commit | 1858163d3ca39b538f847046d781422e5b6026a0 (patch) | |
tree | 0fddb1e72e96f981847de645db5a8982ddd98e02 /Userland | |
parent | 8eeedce8053893f72ad72678a1f5e955f612a03b (diff) | |
download | serenity-1858163d3ca39b538f847046d781422e5b6026a0.zip |
LibIPC: Add a built-in encoder/decoder for AK::Time
Diffstat (limited to 'Userland')
-rw-r--r-- | Userland/Libraries/LibIPC/Decoder.cpp | 7 | ||||
-rw-r--r-- | Userland/Libraries/LibIPC/Decoder.h | 3 | ||||
-rw-r--r-- | Userland/Libraries/LibIPC/Encoder.cpp | 7 | ||||
-rw-r--r-- | Userland/Libraries/LibIPC/Encoder.h | 3 |
4 files changed, 20 insertions, 0 deletions
diff --git a/Userland/Libraries/LibIPC/Decoder.cpp b/Userland/Libraries/LibIPC/Decoder.cpp index 49f7694bfb..6abb1d1d7d 100644 --- a/Userland/Libraries/LibIPC/Decoder.cpp +++ b/Userland/Libraries/LibIPC/Decoder.cpp @@ -63,6 +63,13 @@ ErrorOr<JsonValue> decode(Decoder& decoder) } template<> +ErrorOr<Time> decode(Decoder& decoder) +{ + auto nanoseconds = TRY(decoder.decode<i64>()); + return AK::Time::from_nanoseconds(nanoseconds); +} + +template<> ErrorOr<URL> decode(Decoder& decoder) { auto url = TRY(decoder.decode<DeprecatedString>()); diff --git a/Userland/Libraries/LibIPC/Decoder.h b/Userland/Libraries/LibIPC/Decoder.h index d1ff1b9d54..a2f8a54956 100644 --- a/Userland/Libraries/LibIPC/Decoder.h +++ b/Userland/Libraries/LibIPC/Decoder.h @@ -88,6 +88,9 @@ template<> ErrorOr<JsonValue> decode(Decoder&); template<> +ErrorOr<Time> decode(Decoder&); + +template<> ErrorOr<URL> decode(Decoder&); template<> diff --git a/Userland/Libraries/LibIPC/Encoder.cpp b/Userland/Libraries/LibIPC/Encoder.cpp index 70b67d8c06..358dd02cc9 100644 --- a/Userland/Libraries/LibIPC/Encoder.cpp +++ b/Userland/Libraries/LibIPC/Encoder.cpp @@ -11,6 +11,7 @@ #include <AK/JsonObject.h> #include <AK/JsonValue.h> #include <AK/NumericLimits.h> +#include <AK/Time.h> #include <AK/URL.h> #include <LibCore/AnonymousBuffer.h> #include <LibCore/DateTime.h> @@ -74,6 +75,12 @@ ErrorOr<void> encode(Encoder& encoder, JsonValue const& value) } template<> +ErrorOr<void> encode(Encoder& encoder, Time const& value) +{ + return encoder.encode(value.to_nanoseconds()); +} + +template<> ErrorOr<void> encode(Encoder& encoder, URL const& value) { return encoder.encode(value.to_deprecated_string()); diff --git a/Userland/Libraries/LibIPC/Encoder.h b/Userland/Libraries/LibIPC/Encoder.h index b6a97e2c9d..f379d4d417 100644 --- a/Userland/Libraries/LibIPC/Encoder.h +++ b/Userland/Libraries/LibIPC/Encoder.h @@ -119,6 +119,9 @@ template<> ErrorOr<void> encode(Encoder&, JsonValue const&); template<> +ErrorOr<void> encode(Encoder&, Time const&); + +template<> ErrorOr<void> encode(Encoder&, URL const&); template<> |