Skip to main content

MqttBuilder

Struct MqttBuilder 

Source
pub struct MqttBuilder { /* private fields */ }
Expand description

Builder for MQTT packets.

By default, builds a PINGREQ message (\xC0\x00).

Implementations§

Source§

impl MqttBuilder

Source

pub fn new() -> Self

Create a new MQTT builder. Defaults to PINGREQ (\xC0\x00).

Source

pub fn connect(self) -> Self

Set message type to CONNECT (1).

Source

pub fn connack(self) -> Self

Set message type to CONNACK (2).

Source

pub fn publish(self) -> Self

Set message type to PUBLISH (3).

Source

pub fn puback(self) -> Self

Set message type to PUBACK (4).

Source

pub fn pubrec(self) -> Self

Set message type to PUBREC (5).

Source

pub fn pubrel(self) -> Self

Set message type to PUBREL (6).

Source

pub fn pubcomp(self) -> Self

Set message type to PUBCOMP (7).

Source

pub fn subscribe(self) -> Self

Set message type to SUBSCRIBE (8).

Source

pub fn suback(self) -> Self

Set message type to SUBACK (9).

Source

pub fn unsubscribe(self) -> Self

Set message type to UNSUBSCRIBE (10).

Source

pub fn unsuback(self) -> Self

Set message type to UNSUBACK (11).

Source

pub fn pingreq(self) -> Self

Set message type to PINGREQ (12, the default).

Source

pub fn pingresp(self) -> Self

Set message type to PINGRESP (13).

Source

pub fn disconnect(self) -> Self

Set message type to DISCONNECT (14).

Source

pub fn msg_type(self, t: u8) -> Self

Set the raw message type value.

Source

pub fn dup(self, val: bool) -> Self

Set the DUP flag.

Source

pub fn qos(self, val: u8) -> Self

Set the QoS level.

Source

pub fn retain(self, val: bool) -> Self

Set the RETAIN flag.

Source

pub fn proto_name<T: Into<Vec<u8>>>(self, name: T) -> Self

Set the protocol name (default: “MQTT”).

Source

pub fn proto_level(self, level: u8) -> Self

Set the protocol level (default: 4 for MQTT 3.1.1).

Source

pub fn clean_session(self, val: bool) -> Self

Set the clean session flag.

Source

pub fn will(self, topic: &[u8], msg: &[u8], qos: u8, retain: bool) -> Self

Set the will flag and optionally will topic/message.

Source

pub fn username<T: Into<Vec<u8>>>(self, name: T) -> Self

Set the username.

Source

pub fn password<T: Into<Vec<u8>>>(self, pass: T) -> Self

Set the password.

Source

pub fn keep_alive(self, secs: u16) -> Self

Set the keep alive value (seconds).

Source

pub fn client_id<T: Into<Vec<u8>>>(self, id: T) -> Self

Set the client ID.

Source

pub fn topic<T: Into<Vec<u8>>>(self, t: T) -> Self

Set the topic for PUBLISH.

Source

pub fn msg_id(self, id: u16) -> Self

Set the message ID.

Source

pub fn payload<T: Into<Vec<u8>>>(self, data: T) -> Self

Set the payload/value bytes.

Source

pub fn add_topic(self, filter: &[u8], qos: u8) -> Self

Add a topic filter with requested QoS for SUBSCRIBE.

Source

pub fn retcodes<T: Into<Vec<u8>>>(self, codes: T) -> Self

Set the return codes for SUBACK.

Source

pub fn sess_present(self, val: u8) -> Self

Set the session present flag for CONNACK.

Source

pub fn ret_code(self, code: u8) -> Self

Set the return code for CONNACK.

Source

pub fn remaining_size(&self) -> usize

Compute the size of the variable header + payload (the remaining length).

Source

pub fn header_size(&self) -> usize

Compute the total header size (fixed header bytes only).

Source

pub fn packet_size(&self) -> usize

Compute the total packet size.

Source

pub fn build(&self) -> Vec<u8>

Serialize the MQTT packet into bytes.

Trait Implementations§

Source§

impl Clone for MqttBuilder

Source§

fn clone(&self) -> MqttBuilder

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for MqttBuilder

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for MqttBuilder

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl IntoLayerStackEntry for MqttBuilder

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V