Boost C++ Libraries

PrevUpHomeNext

Struct envelope

boost::taar::jsonrpc::envelope — Parsed JSON-RPC 2.0 request envelope.

Synopsis

// In header: <boost/taar/jsonrpc/envelope.hpp>


struct envelope {

  // public data members
  std::string jsonrpc;  // Always "2.0" for a successfully-parsed envelope. 
  std::string method;  // Method name. Required and non-empty when populated by the parser. 
  std::optional< boost::json::value > id;  // Request id. Empty when the envelope is a notification. 
  std::optional< boost::json::value > params;  // Method parameters. Empty when the envelope omits "params". 
};

Description

Mirrors the spec request object: a fixed "jsonrpc" version of "2.0", a method name, optional structured parameters, and an optional id. An envelope without an id is a notification – the server processes it but produces no response.

The id field is stored as a boost::json::value because the spec allows strings, numbers, and null. Notification envelopes leave the optional empty; requests carry the value verbatim so the response can echo it back unchanged.

params is similarly optional: present requests may omit the field entirely. The spec says when present it MUST be an object or array, but the parser leaves shape validation to handlers (which will report invalid_params on type mismatch) so a future stricter mode can be layered on without breaking the parser's contract.


PrevUpHomeNext