Crate request_response
request-response
only.Expand description
Generic request/response protocols.
§General Usage
The Behaviour
struct is a NetworkBehaviour
that implements a generic
request/response protocol or protocol family, whereby each request is
sent over a new substream on a connection. Behaviour
is generic
over the actual messages being sent, which are defined in terms of a
Codec
. Creating a request/response protocol thus amounts
to providing an implementation of this trait which can then be
given to Behaviour::with_codec
. Further configuration options are
available via the Config
.
Requests are sent using Behaviour::send_request
and the
responses received as Message::Response
via
Event::Message
.
Responses are sent using Behaviour::send_response
upon
receiving a Message::Request
via
Event::Message
.
§Predefined codecs
In case your message types implement serde::Serialize
and serde::Deserialize
,
you can use two predefined behaviours:
cbor::Behaviour
for CBOR-encoded messagesjson::Behaviour
for JSON-encoded messages
§Protocol Families
A single Behaviour
instance can be used with an entire
protocol family that share the same request and response types.
For that purpose, Codec::Protocol
is typically
instantiated with a sum type.
§Limited Protocol Support
It is possible to only support inbound or outbound requests for
a particular protocol. This is achieved by instantiating Behaviour
with protocols using ProtocolSupport::Inbound
or
ProtocolSupport::Outbound
. Any subset of protocols of a protocol
family can be configured in this way. Such protocols will not be
advertised during inbound respectively outbound protocol negotiation
on the substreams.
Modules§
Structs§
- A request/response protocol for some message codec.
- The configuration for a
Behaviour
protocol. - The ID of an inbound request.
- The ID of an outbound request.
- A channel for sending a response to an inbound request.
Enums§
- The events emitted by a request-response
Behaviour
. - Possible failures occurring in the context of receiving an inbound request and sending a response.
- An inbound request or response.
- Possible failures occurring in the context of sending an outbound request and receiving the response.
- The level of support for a particular protocol.
Traits§
- A
Codec
defines the request and response types for a request-responseBehaviour
protocol or protocol family and how they are encoded / decoded on an I/O stream.