1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
use std::sync::Arc;
use super::{QoS, LastWill, PacketIdentifier, Protocol, ConnectReturnCode};

#[derive(Debug, Clone, PartialEq)]
pub enum Packet {
	Connect(Connect),
	Connack(Connack),
	Publish(Publish),
	Puback(PacketIdentifier),
	Pubrec(PacketIdentifier),
	Pubrel(PacketIdentifier),
	Pubcomp(PacketIdentifier),
	Subscribe(Subscribe),
	Suback(Suback),
	Unsubscribe(Unsubscribe),
	Unsuback(PacketIdentifier),
	Pingreq,
	Pingresp,
	Disconnect
}

#[derive(Debug, Clone, PartialEq)]
pub struct Connect {
	pub protocol: Protocol,
    pub keep_alive: u16,
    pub client_id: String,
	pub clean_session: bool,
    pub last_will: Option<LastWill>,
    pub username: Option<String>,
    pub password: Option<String>
}

#[derive(Debug, Clone, Copy, PartialEq)]
pub struct Connack {
    pub session_present: bool,
    pub code: ConnectReturnCode
}

#[derive(Debug, Clone, PartialEq)]
pub struct Publish {
    pub dup: bool,
    pub qos: QoS,
    pub retain: bool,
    pub topic_name: String,
    pub pkid: Option<PacketIdentifier>,
    pub payload: Arc<Vec<u8>>
}

#[derive(Debug, Clone, PartialEq)]
pub struct Subscribe {
    pub pkid: PacketIdentifier,
	// (topic path, qos)
	pub topics: Vec<SubscribeTopic>
}

#[derive(Debug, Clone, PartialEq)]
pub struct SubscribeTopic {
	pub topic_path: String,
	pub qos: QoS
}

#[derive(Debug, Clone, PartialEq)]
pub struct Suback {
    pub pkid: PacketIdentifier,
	// (error, qos)
	// TODO: replace with enum
	pub return_codes: Vec<SubscribeReturnCodes>
}

#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum SubscribeReturnCodes {
	Success(QoS),
	Failure
}

#[derive(Debug, Clone, PartialEq)]
pub struct Unsubscribe {
    pub pkid: PacketIdentifier,
	pub topics: Vec<String>
}