Continue work
This commit is contained in:
parent
d661609e7c
commit
0c773fbf0c
13
src/main.rs
13
src/main.rs
|
@ -1,7 +1,7 @@
|
||||||
use rust_mqtt::packet::mqttpacket::Packet;
|
use rust_mqtt::packet::mqtt_packet::Packet;
|
||||||
|
use rust_mqtt::packet::packet_type::PacketType;
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
|
|
||||||
env_logger::builder()
|
env_logger::builder()
|
||||||
.filter_level(log::LevelFilter::Info)
|
.filter_level(log::LevelFilter::Info)
|
||||||
.format_timestamp_nanos()
|
.format_timestamp_nanos()
|
||||||
|
@ -11,10 +11,13 @@ fn main() {
|
||||||
let y: u32 = 2;
|
let y: u32 = 2;
|
||||||
let z: u16 = 3;
|
let z: u16 = 3;
|
||||||
let p: u32 = 4;
|
let p: u32 = 4;
|
||||||
let text: &'a [u8] = "abcde";
|
|
||||||
let payld: &'a [u8] = "This is payload";
|
|
||||||
|
|
||||||
let x = Packet::new( l, y, z, p, text, payld );
|
let mut txt = *b"abcde";
|
||||||
|
let mut payld = *b"xxxxx";
|
||||||
|
let f = PacketType::Reserved;
|
||||||
|
let o: u8 = f.into();
|
||||||
|
log::info!("Enum val: {}", o);
|
||||||
|
let x = Packet::new( l, y, z, p, &mut txt, &mut payld );
|
||||||
log::info!("Hello world");
|
log::info!("Hello world");
|
||||||
x.encode();
|
x.encode();
|
||||||
x.get_reason_code();
|
x.get_reason_code();
|
||||||
|
|
|
@ -1 +1,2 @@
|
||||||
pub mod mqttpacket;
|
pub mod mqtt_packet;
|
||||||
|
pub mod packet_type;
|
|
@ -15,8 +15,9 @@ pub struct Packet<'a> {
|
||||||
payload: &'a mut [u8]
|
payload: &'a mut [u8]
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> Packet {
|
impl<'a> Packet<'a> {
|
||||||
pub fn new(header_control: u8, remain_len: u32, packet_identifier: u16, property_len: u32, properties: &'a mut [u8], payload: &'a mut [u8]) -> Self {
|
pub fn new(header_control: u8, remain_len: u32, packet_identifier: u16, property_len: u32,
|
||||||
|
properties: &'a mut [u8], payload: &'a mut [u8]) -> Self {
|
||||||
Self { header_control, remain_len, packet_identifier, property_len , properties, payload}
|
Self { header_control, remain_len, packet_identifier, property_len , properties, payload}
|
||||||
}
|
}
|
||||||
|
|
46
src/packet/packet_type.rs
Normal file
46
src/packet/packet_type.rs
Normal file
|
@ -0,0 +1,46 @@
|
||||||
|
// x x x x - - - -
|
||||||
|
|
||||||
|
|
||||||
|
pub enum PacketType {
|
||||||
|
Reserved,
|
||||||
|
Connect,
|
||||||
|
Connack,
|
||||||
|
Publish,
|
||||||
|
Puback,
|
||||||
|
Pubrec,
|
||||||
|
Pubrel,
|
||||||
|
Pubcomp,
|
||||||
|
Subscribe,
|
||||||
|
Suback,
|
||||||
|
Unsubscribe,
|
||||||
|
Unsuback,
|
||||||
|
Pingreq,
|
||||||
|
Pingresp,
|
||||||
|
Disconnect,
|
||||||
|
Auth
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<u8> for PacketType {
|
||||||
|
fn from(orig: u8) -> Self {
|
||||||
|
match orig {
|
||||||
|
0x00 => return PacketType::Reserved,
|
||||||
|
0x10 => return PacketType::Connect,
|
||||||
|
0x20 => return PacketType::Connack,
|
||||||
|
0x30 => return PacketType::Publish,
|
||||||
|
0x40 => return PacketType::Puback,
|
||||||
|
0x50 => return PacketType::Pubrec,
|
||||||
|
0x60 => return PacketType::Pubrel,
|
||||||
|
0x70 => return PacketType::Pubcomp,
|
||||||
|
0x80 => return PacketType::Subscribe,
|
||||||
|
0x90 => return PacketType::Suback,
|
||||||
|
0xA0 => return PacketType::Unsubscribe,
|
||||||
|
0xB0 => return PacketType::Unsuback,
|
||||||
|
0xC0 => return PacketType::Pingreq,
|
||||||
|
0xD0 => return PacketType::Pingresp,
|
||||||
|
0xE0 => return PacketType::Disconnect,
|
||||||
|
0xF0 => return PacketType::Auth,
|
||||||
|
_ => return PacketType::Reserved
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user