/* * Copyright (c) 2022, Tim Flynn * * SPDX-License-Identifier: BSD-2-Clause */ #pragma once #include #include #include #include namespace Web::WebDriver { // FIXME: Ideally, this could be `using Response = ErrorOr`, but that won't be // default-constructible, which is a requirement for the generated IPC. struct Response { Response() = default; Response(JsonValue&&); Response(Error&&); JsonValue& value() { return m_value_or_error.template get(); } JsonValue const& value() const { return m_value_or_error.template get(); } Error& error() { return m_value_or_error.template get(); } Error const& error() const { return m_value_or_error.template get(); } bool is_error() const { return m_value_or_error.template has(); } JsonValue release_value() { return move(value()); } Error release_error() { return move(error()); } template decltype(auto) visit(Visitors&&... visitors) const { return m_value_or_error.visit(forward(visitors)...); } private: // Note: Empty is only a possible state until the Response has been decoded by IPC. Variant m_value_or_error; }; } namespace IPC { template<> bool encode(Encoder&, Web::WebDriver::Response const&); template<> ErrorOr decode(Decoder&, Web::WebDriver::Response&); }