prf::control::ResponseWriter class final

Streaming CBOR map writer for control responses.

Writer appends key/value pairs directly into caller-owned output buffer and never owns payload memory. On overflow, writer enters sticky error state and further appends fail.

Constructors, destructors, conversion operators

ResponseWriter() defaulted
ResponseWriter(std::span<uint8_t> buffer) explicit
Initializes writer over caller-owned output buffer.

Public functions

auto add_bool(std::string_view key, bool value) -> bool
Appends key: bool.
auto add_bytes(std::string_view key, std::span<const uint8_t> value) -> bool
Appends key: bytes.
auto add_double(std::string_view key, double value) -> bool
Appends key: double.
auto add_hex_text(std::string_view key, std::span<const uint8_t> bytes) -> bool
Appends key: "<hex>" where bytes are encoded as lowercase hex text.
auto add_i64(std::string_view key, int64_t value) -> bool
Appends key: int64.
auto add_ipv4_text(std::string_view key, uint32_t ip) -> bool
Appends key: "a.b.c.d" from IPv4 uint32.
auto add_text(std::string_view key, std::string_view value) -> bool
Appends key: text.
auto add_u64(std::string_view key, uint64_t value) -> bool
Appends key: uint64.
auto error_code() const -> const char*
Returns current string error code token, or null in success mode.
auto error_code_enum(ErrorCode* out_code) const -> bool
Returns enum error code when set via set_error(ErrorCode).
auto field_count() const -> size_t
Number of appended fields in current envelope.
auto ok() const -> bool
Returns true when writer is still in success mode.
auto overflowed() const -> bool
Returns true when buffer capacity has been exceeded.
auto payload() const -> std::span<const uint8_t>
Returns encoded payload view in caller buffer.
void reset(std::span<uint8_t> buffer)
Rebinds writer to a new output buffer and clears previous state.
void set_error(const char* code)
Switches payload to error envelope from preformatted string code.
void set_error(ErrorCode code)
Switches payload to error envelope from enum code.
auto wire_add_bool(bool value) -> bool
Appends scalar/byte/text values in wire mode.
auto wire_add_bytes(std::span<const uint8_t> value) -> bool
auto wire_add_double(double value) -> bool
auto wire_add_i64(int64_t value) -> bool
auto wire_add_key_text(std::string_view key) -> bool
Appends text map key.
auto wire_add_key_u64(uint64_t key) -> bool
Appends unsigned integer map key.
auto wire_add_preencoded(std::span<const uint8_t> encoded_item) -> bool
Appends already-encoded CBOR item in wire mode.
auto wire_add_text(std::string_view value) -> bool
auto wire_add_u64(uint64_t value) -> bool
auto wire_begin_array(size_t item_count) -> bool
Appends one array header as value.
auto wire_begin_error_response(std::string_view path, uint64_t error_code, std::string_view error_detail = {}) -> bool
Starts canonical error envelope map.
auto wire_begin_map(size_t pair_count) -> bool
Appends one map header as value.
auto wire_begin_ok_response(protocol::wire::Kind kind, std::string_view path, size_t payload_pairs) -> bool
Starts canonical ok envelope map with fixed payload pair count.
auto wire_reset() -> bool
Resets writer to low-level wire mode without legacy auto-envelopes.
auto wire_start_map(size_t pair_count) -> bool
Starts a new top-level map with fixed number of key/value pairs.