Pulp 1.88.0
Cross-platform audio plugin framework
Loading...
Searching...
No Matches
protocol.hpp
Go to the documentation of this file.
1// protocol.hpp — Inspector protocol: message types and JSON encoding
2// Modeled on Chrome DevTools Protocol with domain.method naming.
3#pragma once
4
5#include <cstddef>
6#include <cstdint>
7#include <string>
8#include <string_view>
10namespace pulp::inspect {
14inline constexpr std::size_t kInspectorExtendedMessageBytes =
15 16u * 1024u * 1024u;
19 int64_t id = 0;
20 std::string method;
21 std::string params_json;
22 bool is_error = false;
23 std::string error_code;
24 std::string error_data_json;
25};
27// ── Encode / Decode ─────────────────────────────────────────────────────
30std::string encode_message(const InspectorMessage& msg);
33bool decode_message(const std::string& json, InspectorMessage& out);
35// ── Factory helpers ─────────────────────────────────────────────────────
36
37InspectorMessage make_request(int64_t id, std::string method, std::string params_json = "{}");
38InspectorMessage make_response(int64_t id, std::string result_json);
39InspectorMessage make_error(int64_t id, std::string error_message,
40 std::string error_code = "internal_error",
41 std::string error_data_json = "{}");
42InspectorMessage make_event(std::string method, std::string params_json = "{}");
44// ── Method name constants ───────────────────────────────────────────────
46namespace methods {
47#define PULP_INSPECT_METHOD(symbol, wire_name, capability, kind) \
48 inline constexpr auto symbol = wire_name;
50#undef PULP_INSPECT_METHOD
53} // namespace pulp::inspect
Definition protocol.hpp:46
Definition agent_context.hpp:7
std::string encode_message(const InspectorMessage &msg)
Serialize a message to a JSON string.
InspectorMessage make_error(int64_t id, std::string error_message, std::string error_code="internal_error", std::string error_data_json="{}")
bool decode_message(const std::string &json, InspectorMessage &out)
Parse a JSON string into a message. Returns false on parse failure.
InspectorMessage make_request(int64_t id, std::string method, std::string params_json="{}")
constexpr std::size_t kInspectorExtendedMessageBytes
Bounded transfer ceiling used by clients and by hosts that expose image capture.
Definition protocol.hpp:14
InspectorMessage make_response(int64_t id, std::string result_json)
InspectorMessage make_event(std::string method, std::string params_json="{}")
A single inspector protocol message (request, response, or event).
Definition protocol.hpp:18
bool is_error
True if this is an error response.
Definition protocol.hpp:22
std::string error_code
Stable machine-readable code for error responses.
Definition protocol.hpp:23
std::string params_json
JSON object string (params for request, result for response).
Definition protocol.hpp:21
std::string method
"Domain.method" — e.g. "DOM.getDocument"
Definition protocol.hpp:20
std::string error_data_json
Optional structured error details.
Definition protocol.hpp:24