summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibIPC
diff options
context:
space:
mode:
authorTimothy Flynn <trflynn89@pm.me>2023-02-24 13:51:37 -0500
committerTim Flynn <trflynn89@pm.me>2023-02-24 15:50:42 -0500
commit1858163d3ca39b538f847046d781422e5b6026a0 (patch)
tree0fddb1e72e96f981847de645db5a8982ddd98e02 /Userland/Libraries/LibIPC
parent8eeedce8053893f72ad72678a1f5e955f612a03b (diff)
downloadserenity-1858163d3ca39b538f847046d781422e5b6026a0.zip
LibIPC: Add a built-in encoder/decoder for AK::Time
Diffstat (limited to 'Userland/Libraries/LibIPC')
-rw-r--r--Userland/Libraries/LibIPC/Decoder.cpp7
-rw-r--r--Userland/Libraries/LibIPC/Decoder.h3
-rw-r--r--Userland/Libraries/LibIPC/Encoder.cpp7
-rw-r--r--Userland/Libraries/LibIPC/Encoder.h3
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<>