dfx 0.1.0
Linux-based dynamic dataflow executor
Loading...
Searching...
No Matches
Message.hpp
1// SPDX-FileCopyrightText: 2025 Vincent Leroy
2// SPDX-License-Identifier: MIT
3//
4// This file is part of dfx.
5//
6// Licensed under the MIT License. See the LICENSE file in the project root
7// for full license information.
8
9#pragma once
10
11// Standard includes
12#include <vector>
13
14// Third-party includes
15#include <nlohmann/json.hpp>
16
17// Project includes
19
20namespace dfx::Client
21{
38{
39public:
41 enum class Type
42 {
45 };
46
47public:
53 explicit Message(nlohmann::json json);
54
55public:
57 bool isOk() const noexcept { return _type == Type::Success; }
59 bool isError() const noexcept { return _type == Type::Error; }
61 Type type() const noexcept { return _type; }
62
64 nlohmann::json const & json() const noexcept { return _json; }
65
67 nlohmann::json result() const noexcept;
69 std::vector<std::string> errors() const;
70
71private:
72 Type _type;
73 nlohmann::json _json;
74};
75} // !namespace dfx::Client
76
Macro-based enum <-> string utilities for dfx.
#define DECLARE_ENUM_STRING_FUNCTIONS(E)
Declare the enum string API (and std::formatter) for enum type E.
Definition EnumString.hpp:327
Type
High-level message category.
Definition Message.hpp:42
@ Success
Message represents a successful response.
Definition Message.hpp:43
@ Error
Message represents a failure response.
Definition Message.hpp:44
Type type() const noexcept
Return the message type determined at construction.
Definition Message.hpp:61
nlohmann::json result() const noexcept
Extract the "result" portion (if any) of the message.
std::vector< std::string > errors() const
Extract the error list from the message.
nlohmann::json const & json() const noexcept
Access the underlying JSON payload (read-only).
Definition Message.hpp:64
bool isError() const noexcept
True if this message represents an error response.
Definition Message.hpp:59
bool isOk() const noexcept
True if this message represents a successful response.
Definition Message.hpp:57
Message(nlohmann::json json)
Construct a message wrapper from a JSON payload.
Definition Message.hpp:21
Definition Message.hpp:21
STL namespace.