mirror of
https://github.com/SerenityOS/serenity.git
synced 2025-01-24 18:32:28 -05: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:
parent
a1baa5cb00
commit
a7bb72a3d6
4 changed files with 29 additions and 0 deletions
|
@ -1,5 +1,6 @@
|
|||
/*
|
||||
* Copyright (c) 2020, Andreas Kling <kling@serenityos.org>
|
||||
* Copyright (c) 2023, Tim Flynn <trflynn89@serenityos.org>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
@ -23,6 +24,13 @@ ErrorOr<size_t> Decoder::decode_size()
|
|||
return static_cast<size_t>(TRY(decode<u32>()));
|
||||
}
|
||||
|
||||
template<>
|
||||
ErrorOr<String> decode(Decoder& decoder)
|
||||
{
|
||||
auto length = TRY(decoder.decode_size());
|
||||
return String::from_stream(decoder.stream(), length);
|
||||
}
|
||||
|
||||
template<>
|
||||
ErrorOr<DeprecatedString> decode(Decoder& decoder)
|
||||
{
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
/*
|
||||
* Copyright (c) 2020, Andreas Kling <kling@serenityos.org>
|
||||
* Copyright (c) 2023, Tim Flynn <trflynn89@serenityos.org>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
@ -11,6 +12,7 @@
|
|||
#include <AK/Forward.h>
|
||||
#include <AK/NumericLimits.h>
|
||||
#include <AK/StdLibExtras.h>
|
||||
#include <AK/String.h>
|
||||
#include <AK/Try.h>
|
||||
#include <AK/TypeList.h>
|
||||
#include <AK/Variant.h>
|
||||
|
@ -56,6 +58,7 @@ public:
|
|||
|
||||
ErrorOr<size_t> decode_size();
|
||||
|
||||
Stream& stream() { return m_stream; }
|
||||
Core::LocalSocket& socket() { return m_socket; }
|
||||
|
||||
private:
|
||||
|
@ -78,6 +81,9 @@ ErrorOr<T> decode(Decoder& decoder)
|
|||
return static_cast<T>(value);
|
||||
}
|
||||
|
||||
template<>
|
||||
ErrorOr<String> decode(Decoder&);
|
||||
|
||||
template<>
|
||||
ErrorOr<DeprecatedString> decode(Decoder&);
|
||||
|
||||
|
|
|
@ -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)
|
||||
{
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
/*
|
||||
* Copyright (c) 2018-2021, Andreas Kling <kling@serenityos.org>
|
||||
* Copyright (c) 2023, Tim Flynn <trflynn89@serenityos.org>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
@ -106,6 +107,9 @@ ErrorOr<void> encode(Encoder&, float const&);
|
|||
template<>
|
||||
ErrorOr<void> encode(Encoder&, double const&);
|
||||
|
||||
template<>
|
||||
ErrorOr<void> encode(Encoder&, String const&);
|
||||
|
||||
template<>
|
||||
ErrorOr<void> encode(Encoder&, StringView const&);
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue