pub struct ConnectPacket { /* private fields */ }Expand description
ConnectPacket consists of three parts:
FixedHeaderVariableHeaderPayloadNote 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
impl ConnectPacket
Sourcepub fn new(client_id: &str) -> Result<Self, EncodeError>
pub fn new(client_id: &str) -> Result<Self, EncodeError>
Sourcepub fn new_v3(client_id: &str) -> Result<Self, EncodeError>
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.
Sourcepub fn set_protcol_level(
&mut self,
level: ProtocolLevel,
) -> Result<(), EncodeError>
pub fn set_protcol_level( &mut self, level: ProtocolLevel, ) -> Result<(), EncodeError>
Sourcepub const fn protocol_level(&self) -> ProtocolLevel
pub const fn protocol_level(&self) -> ProtocolLevel
Get current protocol level.
Sourcepub fn set_connect_flags(&mut self, flags: ConnectFlags) -> &Self
pub fn set_connect_flags(&mut self, flags: ConnectFlags) -> &Self
Update connect flags
Sourcepub const fn connect_flags(&self) -> &ConnectFlags
pub const fn connect_flags(&self) -> &ConnectFlags
Get current connect flags.
Sourcepub fn set_keep_alive(&mut self, keep_alive: u16) -> &mut Self
pub fn set_keep_alive(&mut self, keep_alive: u16) -> &mut Self
Update keep alive value in milliseconds.
Sourcepub const fn keep_alive(&self) -> u16
pub const fn keep_alive(&self) -> u16
Get current keep alive value.
Sourcepub fn set_client_id(
&mut self,
client_id: &str,
) -> Result<&mut Self, EncodeError>
pub fn set_client_id( &mut self, client_id: &str, ) -> Result<&mut Self, EncodeError>
Sourcepub fn set_username(&mut self, username: &str) -> Result<&mut Self, EncodeError>
pub fn set_username(&mut self, username: &str) -> Result<&mut Self, EncodeError>
Sourcepub fn set_password(
&mut self,
password: &[u8],
) -> Result<&mut Self, EncodeError>
pub fn set_password( &mut self, password: &[u8], ) -> Result<&mut Self, EncodeError>
Sourcepub fn set_will_topic(&mut self, topic: &str) -> Result<&mut Self, EncodeError>
pub fn set_will_topic(&mut self, topic: &str) -> Result<&mut Self, EncodeError>
Sourcepub fn will_topic(&self) -> Option<&str>
pub fn will_topic(&self) -> Option<&str>
Get current will-topic value.
Sourcepub fn set_will_message(
&mut self,
message: &[u8],
) -> Result<&mut Self, EncodeError>
pub fn set_will_message( &mut self, message: &[u8], ) -> Result<&mut Self, EncodeError>
Sourcepub fn will_message(&self) -> &[u8] ⓘ
pub fn will_message(&self) -> &[u8] ⓘ
Get current will-message value.
Trait Implementations§
Source§impl Clone for ConnectPacket
impl Clone for ConnectPacket
Source§fn clone(&self) -> ConnectPacket
fn clone(&self) -> ConnectPacket
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for ConnectPacket
impl Debug for ConnectPacket
Source§impl DecodePacket for ConnectPacket
impl DecodePacket for ConnectPacket
Source§impl Default for ConnectPacket
impl Default for ConnectPacket
Source§fn default() -> ConnectPacket
fn default() -> ConnectPacket
Returns the “default value” for a type. Read more
Source§impl EncodePacket for ConnectPacket
impl EncodePacket for ConnectPacket
Source§impl Packet for ConnectPacket
impl Packet for ConnectPacket
fn packet_type(&self) -> PacketType
Source§impl PartialEq for ConnectPacket
impl PartialEq for ConnectPacket
impl Eq for ConnectPacket
impl StructuralPartialEq for ConnectPacket
Auto Trait Implementations§
impl Freeze for ConnectPacket
impl RefUnwindSafe for ConnectPacket
impl Send for ConnectPacket
impl Sync for ConnectPacket
impl Unpin for ConnectPacket
impl UnwindSafe for ConnectPacket
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more