[][src]Enum mqtt_packet::PacketType

#[repr(u8)]
pub enum PacketType {
    CONNECT,
    CONNACK,
    PUBLISH,
    PUBACK,
    PUBREC,
    PUBREL,
    PUBCOMP,
    SUBSCRIBE,
    SUBACK,
    UNSUBSCRIBE,
    UNSUBACK,
    PINGREQ,
    PINGRESP,
    DISCONNECT,
    AUTH,
}

Variants

CONNECT

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Methods

impl PacketType[src]

2.1.2 MQTT Control Packet type

Position: byte 1, bits 7-4. Represented as a 4-bit unsigned value.

pub fn new<R: Read>(reader: &mut R) -> Result<Self, Error>[src]

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

impl From<PacketType> for u8[src]

impl Clone for PacketType[src]

impl Copy for PacketType[src]

impl Eq for PacketType[src]

impl Ord for PacketType[src]

impl PartialEq<PacketType> for PacketType[src]

impl PartialOrd<PacketType> for PacketType[src]

impl Debug for PacketType[src]

impl TryFrom<u8> for PacketType[src]

type Error = Error

The type returned in the event of a conversion error.

impl Hash for PacketType[src]

impl StructuralPartialEq for PacketType[src]

impl StructuralEq for PacketType[src]

Auto Trait Implementations

Blanket Implementations

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> From<T> for T[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> Any for T where
    T: 'static + ?Sized
[src]