1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-26 00:27:43 +00:00

AK+LibIPC: Add a convenience encoder/decoder for JsonValue

This requires that JsonValue is implicitly default-constructible.
This commit is contained in:
Timothy Flynn 2022-11-07 16:30:55 -05:00 committed by Tim Flynn
parent 08750f69e4
commit 3994a79718
5 changed files with 21 additions and 1 deletions

View file

@ -4,6 +4,7 @@
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <AK/JsonValue.h>
#include <AK/MemoryStream.h>
#include <AK/URL.h>
#include <LibCore/AnonymousBuffer.h>
@ -128,6 +129,14 @@ ErrorOr<void> Decoder::decode(ByteBuffer& value)
return m_stream.try_handle_any_error();
}
ErrorOr<void> Decoder::decode(JsonValue& value)
{
String string;
TRY(decode(string));
value = TRY(JsonValue::from_string(string));
return {};
}
ErrorOr<void> Decoder::decode(URL& value)
{
String string;