/* * Copyright (c) 2020, Andreas Kling * Copyright (c) 2023, Tim Flynn * * SPDX-License-Identifier: BSD-2-Clause */ #include #include #include #include #include #include #include #include #include #include #include namespace IPC { ErrorOr Decoder::decode_size() { return static_cast(TRY(decode())); } template<> ErrorOr decode(Decoder& decoder) { auto length = TRY(decoder.decode_size()); return String::from_stream(decoder.stream(), length); } template<> ErrorOr decode(Decoder& decoder) { auto length = TRY(decoder.decode_size()); if (length == NumericLimits::max()) return DeprecatedString {}; if (length == 0) return DeprecatedString::empty(); char* text_buffer = nullptr; auto text_impl = StringImpl::create_uninitialized(length, text_buffer); Bytes bytes { text_buffer, length }; TRY(decoder.decode_into(bytes)); return DeprecatedString { *text_impl }; } template<> ErrorOr decode(Decoder& decoder) { auto length = TRY(decoder.decode_size()); if (length == 0) return ByteBuffer {}; auto buffer = TRY(ByteBuffer::create_uninitialized(length)); auto bytes = buffer.bytes(); TRY(decoder.decode_into(bytes)); return buffer; } template<> ErrorOr decode(Decoder& decoder) { auto json = TRY(decoder.decode()); return JsonValue::from_string(json); } template<> ErrorOr