Boost C++ Libraries

PrevUpHomeNext

Struct rpc_arg

boost::taar::jsonrpc::rpc_arg — Argument provider reading one member of the envelope's params: by name when params is an object, by position when it is an array.

Synopsis

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


struct rpc_arg {

  // public member functions
  explicit rpc_arg(std::string, std::string = {});
  std::string const & name() const noexcept;
  std::string const & description() const noexcept;
  taar::result< boost::json::value > 
  operator()(call const &, matcher::context const &) const;
};

Description

Positions count only the rpc_arg providers of a method, in order, so HTTP providers (header_arg, ...) mixed in do not shift them. A short array leaves trailing parameters missing (an error unless they are optional or defaulted); extra elements are ignored.

The value is converted to the callable's parameter type through rest_arg_cast (so int, double, bool, std::string, boost::json::value, and user types with boost::json::value_to support all work). Wrap in with_default or use a std::optional<T> parameter to make it optional.

An absent parameter is reported as taar::error::argument_not_found (without a message, so optional and defaulted parameters stay cheap); scalar params as jsonrpc::error::invalid_params. The binder wraps either in an invalid_argument_format failure naming the parameter and its position.

The optional description is not sent on the wire; it feeds generators (MCP inputSchema, OpenAPI) that describe the method.

rpc_arg public member functions

  1. explicit rpc_arg(std::string name, std::string description = {});
  2. std::string const & name() const noexcept;
  3. std::string const & description() const noexcept;
  4. taar::result< boost::json::value > 
    operator()(call const & c, matcher::context const &) const;

PrevUpHomeNext