Skip to main content

GenericRequest

pub trait GenericRequest:
    Encode
    + Decode
    + Send
    + Sync
    + 'static {
    type Response: Encode + Decode + Send + Sync + 'static;

    const PROTOCOL_NAME: &'static str;
    const LOG_TARGET: &'static str;

    // Provided methods
    fn encode_response(response: &Self::Response) -> Option<ResponsePayload> { ... }
    fn decode_response(
        payload: SharedAlignedBuffer<Align1>,
    ) -> Result<Self::Response, Error> { ... }
}
Expand description

Generic request with associated response

Required Associated Constants§

Source

const PROTOCOL_NAME: &'static str

Defines request-response protocol name.

Source

const LOG_TARGET: &'static str

Specifies log-parameters for tracing.

Required Associated Types§

Source

type Response: Encode + Decode + Send + Sync + 'static

Response type that corresponds to this request

Provided Methods§

Source

fn encode_response(response: &Self::Response) -> Option<ResponsePayload>

Encode a response into a payload, which must be decodable with Self::decode_response().

The default implementation encodes the response with SCALE codec, responses that contain large buffers can be encoded the same way without copying them into the payload instead.

Returns None if the response is too large.

Source

fn decode_response( payload: SharedAlignedBuffer<Align1>, ) -> Result<Self::Response, Error>

Decode a response received from a remote peer, the whole payload must be consumed.

The default implementation decodes the response with SCALE codec, responses that contain large buffers can reference them in the payload without copying them instead.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§

Source§

impl GenericRequest for CachedPieceByIndexRequest

Source§

const PROTOCOL_NAME: &'static str = "/subspace/cached-piece-by-index/0.1.0"

Source§

const LOG_TARGET: &'static str = "cached-piece-by-index-request-response-handler"

Source§

type Response = CachedPieceByIndexResponse

Source§

impl GenericRequest for PieceByIndexRequest

Source§

const PROTOCOL_NAME: &'static str = "/subspace/piece-by-index/0.1.0"

Source§

const LOG_TARGET: &'static str = "piece-by-index-request-response-handler"

Source§

type Response = PieceByIndexResponse

Source§

impl GenericRequest for SuperSegmentHeaderRequest

Source§

const PROTOCOL_NAME: &'static str = "/subspace/super-segment-headers-by-indexes/0.1.0"

Source§

const LOG_TARGET: &'static str = "super-segment-headers-by-indexes-request-response-handler"

Source§

type Response = SuperSegmentHeaderResponse