ConnectPacket

Struct ConnectPacket 

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

ConnectPacket consists of three parts:

  • FixedHeader
  • VariableHeader
  • Payload Note that fixed header part is same in all packets so that we just ignore it.

Basic struct of ConnectPacket is as below:

 7                          0
+----------------------------+
| Fixed header               |
|                            |
+----------------------------+
| Protocol name              |
|                            |
+----------------------------+
| Protocol level             |
+----------------------------+
| Connect flags              |
+----------------------------+
| Keep alive                 |
|                            |
+----------------------------+
| Client id length           |
|                            |
+----------------------------+
| Client id string ...       |
+----------------------------+
| Will topic length          |
|                            |
+----------------------------+
| Will topic string ...      |
+----------------------------+
| Will message length        |
|                            |
+----------------------------+
| Will message bytes ...     |
+----------------------------+
| Username length            |
|                            |
+----------------------------+
| Username string ...        |
+----------------------------+
| Password length            |
|                            |
+----------------------------+
| Password bytes ...         |
+----------------------------+

Implementations§

Source§

impl ConnectPacket

Source

pub fn new(client_id: &str) -> Result<Self, EncodeError>

Create a new connect packet with client_id.

§Errors

Returns error if client_id is invalid.

Source

pub fn new_v3(client_id: &str) -> Result<Self, EncodeError>

Create a new connect packet with client_id with mqtt 3.1 protocol.

§Errors

Returns error if client_id is invalid.

Source

pub fn set_protcol_level( &mut self, level: ProtocolLevel, ) -> Result<(), EncodeError>

Update protocol level.

§Errors

Returns error if set protocol to MQTT v5.

Source

pub const fn protocol_level(&self) -> ProtocolLevel

Get current protocol level.

Source

pub fn set_connect_flags(&mut self, flags: ConnectFlags) -> &Self

Update connect flags

Source

pub const fn connect_flags(&self) -> &ConnectFlags

Get current connect flags.

Source

pub fn set_keep_alive(&mut self, keep_alive: u16) -> &mut Self

Update keep alive value in milliseconds.

Source

pub const fn keep_alive(&self) -> u16

Get current keep alive value.

Source

pub fn set_client_id( &mut self, client_id: &str, ) -> Result<&mut Self, EncodeError>

Update client id.

§Errors

Returns error if client_id is invalid.

Source

pub fn client_id(&self) -> &str

Get current client id.

Source

pub fn set_username(&mut self, username: &str) -> Result<&mut Self, EncodeError>

Update username value.

§Errors

Returns error if username contains invalid chars or too long.

Source

pub fn username(&self) -> &str

Get current username value.

Source

pub fn set_password( &mut self, password: &[u8], ) -> Result<&mut Self, EncodeError>

Update password value.

§Errors

Returns error if password is too long.

Source

pub fn password(&self) -> &[u8]

Get current password value.

Source

pub fn set_will_topic(&mut self, topic: &str) -> Result<&mut Self, EncodeError>

Update will-topic.

§Errors

Returns error if topic is invalid.

Source

pub fn will_topic(&self) -> Option<&str>

Get current will-topic value.

Source

pub fn set_will_message( &mut self, message: &[u8], ) -> Result<&mut Self, EncodeError>

Update will-message.

§Errors

Returns error if message is too long.

Source

pub fn will_message(&self) -> &[u8]

Get current will-message value.

Trait Implementations§

Source§

impl Clone for ConnectPacket

Source§

fn clone(&self) -> ConnectPacket

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 ConnectPacket

Source§

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

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

impl DecodePacket for ConnectPacket

Source§

fn decode(ba: &mut ByteArray<'_>) -> Result<Self, DecodeError>

Decode byte array into a mqtt packet. Read more
Source§

impl Default for ConnectPacket

Source§

fn default() -> ConnectPacket

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

impl EncodePacket for ConnectPacket

Source§

fn encode(&self, v: &mut Vec<u8>) -> Result<usize, EncodeError>

Encode packets into byte array. Read more
Source§

impl Packet for ConnectPacket

Source§

fn packet_type(&self) -> PacketType

Source§

fn bytes(&self) -> Result<usize, VarIntError>

Get byte length in packet. Read more
Source§

impl PartialEq for ConnectPacket

Source§

fn eq(&self, other: &ConnectPacket) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Eq for ConnectPacket

Source§

impl StructuralPartialEq for ConnectPacket

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> 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