/* * Copyright (c) 2020, Andreas Kling * Copyright (c) 2023, Tim Flynn * * SPDX-License-Identifier: BSD-2-Clause */ #pragma once #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include namespace IPC { template inline ErrorOr decode(Decoder&) { static_assert(DependentFalse, "Base IPC::decoder() instantiated"); VERIFY_NOT_REACHED(); } class Decoder { public: Decoder(Stream& stream, Core::LocalSocket& socket) : m_stream(stream) , m_socket(socket) { } template ErrorOr decode(); template ErrorOr decode_into(T& value) { value = TRY(m_stream.read_value()); return {}; } ErrorOr decode_into(Bytes bytes) { TRY(m_stream.read_entire_buffer(bytes)); return {}; } ErrorOr decode_size(); Stream& stream() { return m_stream; } Core::LocalSocket& socket() { return m_socket; } private: Stream& m_stream; Core::LocalSocket& m_socket; }; template ErrorOr decode(Decoder& decoder) { T value { 0 }; TRY(decoder.decode_into(value)); return value; } template ErrorOr decode(Decoder& decoder) { auto value = TRY(decoder.decode>()); return static_cast(value); } template<> ErrorOr decode(Decoder&); template<> ErrorOr decode(Decoder&); template<> ErrorOr decode(Decoder&); template<> ErrorOr decode(Decoder&); template<> ErrorOr