1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 11:58:12 +00:00

LibIPC: Support transferring String over IPC

Note that unlike the StringView encoder, we do not handle any "null"
state, as the new String cannot be null.
This commit is contained in:
Timothy Flynn 2023-03-05 15:22:38 -05:00 committed by Linus Groh
parent a1baa5cb00
commit a7bb72a3d6
4 changed files with 29 additions and 0 deletions

View file

@ -1,6 +1,7 @@
/*
* Copyright (c) 2020, Andreas Kling <kling@serenityos.org>
* Copyright (c) 2021, kleines Filmröllchen <filmroellchen@serenityos.org>
* Copyright (c) 2023, Tim Flynn <trflynn89@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
@ -11,6 +12,7 @@
#include <AK/JsonObject.h>
#include <AK/JsonValue.h>
#include <AK/NumericLimits.h>
#include <AK/String.h>
#include <AK/Time.h>
#include <AK/URL.h>
#include <LibCore/AnonymousBuffer.h>
@ -42,6 +44,15 @@ ErrorOr<void> encode(Encoder& encoder, double const& value)
return encoder.encode(bit_cast<u64>(value));
}
template<>
ErrorOr<void> encode(Encoder& encoder, String const& value)
{
auto bytes = value.bytes();
TRY(encoder.encode_size(bytes.size()));
TRY(encoder.append(bytes.data(), bytes.size()));
return {};
}
template<>
ErrorOr<void> encode(Encoder& encoder, StringView const& value)
{