#[repr(u8)]pub enum PacketType {
Show 15 variants
CONNECT = 1,
CONNACK = 2,
PUBLISH = 3,
PUBACK = 4,
PUBREC = 5,
PUBREL = 6,
PUBCOMP = 7,
SUBSCRIBE = 8,
SUBACK = 9,
UNSUBSCRIBE = 10,
UNSUBACK = 11,
PINGREQ = 12,
PINGRESP = 13,
DISCONNECT = 14,
AUTH = 15,
}
Variants§
CONNECT = 1
§Examples
use std::convert::TryFrom;
use mqtt_packet::PacketType;
let id = PacketType::CONNECT;
assert_eq!(u8::from(id), 1);
assert_eq!(PacketType::try_from(1).unwrap(), id);
CONNACK = 2
§Examples
use std::convert::TryFrom;
use mqtt_packet::PacketType;
let id = PacketType::CONNACK;
assert_eq!(u8::from(id), 2);
assert_eq!(PacketType::try_from(2).unwrap(), id);
PUBLISH = 3
§Examples
use std::convert::TryFrom;
use mqtt_packet::PacketType;
let id = PacketType::PUBLISH;
assert_eq!(u8::from(id), 3);
assert_eq!(PacketType::try_from(3).unwrap(), id);
PUBACK = 4
§Examples
use std::convert::TryFrom;
use mqtt_packet::PacketType;
let id = PacketType::PUBACK;
assert_eq!(u8::from(id), 4);
assert_eq!(PacketType::try_from(4).unwrap(), id);
PUBREC = 5
§Examples
use std::convert::TryFrom;
use mqtt_packet::PacketType;
let id = PacketType::PUBREC;
assert_eq!(u8::from(id), 5);
assert_eq!(PacketType::try_from(5).unwrap(), id);
PUBREL = 6
§Examples
use std::convert::TryFrom;
use mqtt_packet::PacketType;
let id = PacketType::PUBREL;
assert_eq!(u8::from(id), 6);
assert_eq!(PacketType::try_from(6).unwrap(), id);
PUBCOMP = 7
§Examples
use std::convert::TryFrom;
use mqtt_packet::PacketType;
let id = PacketType::PUBCOMP;
assert_eq!(u8::from(id), 7);
assert_eq!(PacketType::try_from(7).unwrap(), id);
SUBSCRIBE = 8
§Examples
use std::convert::TryFrom;
use mqtt_packet::PacketType;
let id = PacketType::SUBSCRIBE;
assert_eq!(u8::from(id), 8);
assert_eq!(PacketType::try_from(8).unwrap(), id);
SUBACK = 9
§Examples
use std::convert::TryFrom;
use mqtt_packet::PacketType;
let id = PacketType::SUBACK;
assert_eq!(u8::from(id), 9);
assert_eq!(PacketType::try_from(9).unwrap(), id);
UNSUBSCRIBE = 10
§Examples
use std::convert::TryFrom;
use mqtt_packet::PacketType;
let id = PacketType::UNSUBSCRIBE;
assert_eq!(u8::from(id), 10);
assert_eq!(PacketType::try_from(10).unwrap(), id);
UNSUBACK = 11
§Examples
use std::convert::TryFrom;
use mqtt_packet::PacketType;
let id = PacketType::UNSUBACK;
assert_eq!(u8::from(id), 11);
assert_eq!(PacketType::try_from(11).unwrap(), id);
PINGREQ = 12
§Examples
use std::convert::TryFrom;
use mqtt_packet::PacketType;
let id = PacketType::PINGREQ;
assert_eq!(u8::from(id), 12);
assert_eq!(PacketType::try_from(12).unwrap(), id);
PINGRESP = 13
§Examples
use std::convert::TryFrom;
use mqtt_packet::PacketType;
let id = PacketType::PINGRESP;
assert_eq!(u8::from(id), 13);
assert_eq!(PacketType::try_from(13).unwrap(), id);
DISCONNECT = 14
§Examples
use std::convert::TryFrom;
use mqtt_packet::PacketType;
let id = PacketType::DISCONNECT;
assert_eq!(u8::from(id), 14);
assert_eq!(PacketType::try_from(14).unwrap(), id);
AUTH = 15
§Examples
use std::convert::TryFrom;
use mqtt_packet::PacketType;
let id = PacketType::AUTH;
assert_eq!(u8::from(id), 15);
assert_eq!(PacketType::try_from(15).unwrap(), id);
Implementations§
Source§impl PacketType
impl PacketType
Position: byte 1, bits 7-4. Represented as a 4-bit unsigned value.
Sourcepub fn new<R: Read>(reader: &mut R) -> Result<Self, Error>
pub fn new<R: Read>(reader: &mut R) -> Result<Self, Error>
Parse property values from a reader into DataType variants.
§Examples
use mqtt_packet::PacketType;
use mqtt_packet::Error;
use std::io;
let bytes: Vec<u8> = vec![0x10];
let mut reader = io::BufReader::new(&bytes[..]);
let packet_type = PacketType::new(&mut reader).unwrap();
assert_eq!(packet_type, PacketType::CONNECT);
Error:
use mqtt_packet::PacketType;
use mqtt_packet::Error;
use std::io;
let err_bytes: Vec<u8> = vec![0x00];
let mut err_reader = io::BufReader::new(&err_bytes[..]);
let err = PacketType::new(&mut err_reader).unwrap_err();
assert_eq!(err, Error::GenerateError)
Trait Implementations§
Source§impl Clone for PacketType
impl Clone for PacketType
Source§fn clone(&self) -> PacketType
fn clone(&self) -> PacketType
Returns a copy 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 PacketType
impl Debug for PacketType
Source§impl From<PacketType> for u8
impl From<PacketType> for u8
Source§fn from(t: PacketType) -> Self
fn from(t: PacketType) -> Self
Converts to this type from the input type.
Source§impl Hash for PacketType
impl Hash for PacketType
Source§impl Ord for PacketType
impl Ord for PacketType
Source§fn cmp(&self, other: &PacketType) -> Ordering
fn cmp(&self, other: &PacketType) -> Ordering
1.21.0 · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Compares and returns the maximum of two values. Read more
Source§impl PartialEq for PacketType
impl PartialEq for PacketType
Source§impl PartialOrd for PacketType
impl PartialOrd for PacketType
Source§impl TryFrom<u8> for PacketType
impl TryFrom<u8> for PacketType
impl Copy for PacketType
impl Eq for PacketType
impl StructuralPartialEq for PacketType
Auto Trait Implementations§
impl Freeze for PacketType
impl RefUnwindSafe for PacketType
impl Send for PacketType
impl Sync for PacketType
impl Unpin for PacketType
impl UnwindSafe for PacketType
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