Skip to main content

Request

Trait Request 

pub trait Request {
    type Response: for<'a> TryFrom<&'a Message, Error = DecodeError>;
    type Service: Service;

    const ID: u16;
    const TIMEOUT: Option<Duration> = None;

    // Required method
    fn encode(&self, tlvs: &mut TlvWriter);

    // Provided method
    fn decode_response(response: Message) -> Result<Self::Response, Error> { ... }
}
Expand description

A request to a QMI service.

Send it with Client::request. By default, the response contains the result in TLV 0x02, see Status. Override decode_response for a response without it.

§Example

use ql_qmi::codec::{DecodeError, Request, TlvWriter, Utf8Bytes};
use ql_qmi::{Message, Service};

/// Device Management Service.
pub struct Dms;

impl Service for Dms {
    const ID: u32 = 0x02;
    const VERSION: u8 = 1;
}

/// Reads the firmware revision.
struct GetRevision;

struct Revision(Utf8Bytes);

impl Request for GetRevision {
    const ID: u16 = 0x0023;
    type Response = Revision;
    type Service = Dms;

    fn encode(&self, _tlvs: &mut TlvWriter) {}
}

impl TryFrom<&Message> for Revision {
    type Error = DecodeError;

    fn try_from(message: &Message) -> Result<Self, DecodeError> {
        message.get(0x01).map(Self)
    }
}

Required Associated Constants§

const ID: u16

Message ID.

Provided Associated Constants§

const TIMEOUT: Option<Duration> = None

Timeout of the request, if it differs from the client’s default.

Required Associated Types§

type Response: for<'a> TryFrom<&'a Message, Error = DecodeError>

Response message.

type Service: Service

Service that the request belongs to.

Required Methods§

fn encode(&self, tlvs: &mut TlvWriter)

Writes the TLVs of the request.

Provided Methods§

fn decode_response(response: Message) -> Result<Self::Response, Error>

Checks and decodes the response.

The default reads the Status from TLV 0x02 and decodes the response if it reports success.

§Errors

The default returns Error::Rejected if the status reports a failure, or Error::Decode if the status or the response can’t be decoded.

Dyn Compatibility§

This trait is not dyn compatible.

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

Implementors§