Boost C++ Libraries

PrevUpHomeNext

Function parse_envelope

boost::taar::jsonrpc::parse_envelope — Parse a JSON value as a JSON-RPC 2.0 request envelope.

Synopsis

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


boost::system::result< envelope > 
parse_envelope(boost::json::value const & value);

Description

Validates the spec's required structure: value must be a JSON object, must contain a "jsonrpc" string equal to "2.0", and must contain a "method" string. The "id" and "params" fields are copied into the result when present and left empty otherwise.

Batch requests (top-level arrays of envelopes) are not handled here. jsonrpc::endpoint iterates a parsed array and invokes this function per element; per the specification, an empty batch is reported as a single invalid_request response.

Returns:

A populated envelope on success, or boost::taar::jsonrpc::error::invalid_request on any structural error. Note that JSON-level parse failure is outside this function's scope – callers that hand-roll JSON parsing should map boost::json::parse errors to error::parse_error themselves.


PrevUpHomeNext