More work
This commit is contained in:
parent
f0b9a1a272
commit
7446fcba04
|
@ -4,6 +4,7 @@
|
|||
#![allow(dead_code)]
|
||||
|
||||
pub mod packet;
|
||||
pub mod encoding;
|
||||
|
||||
#[allow(unused_variables)]
|
||||
pub fn print_stack(file: &'static str, line: u32) {
|
||||
|
|
15
src/main.rs
15
src/main.rs
|
@ -1,5 +1,7 @@
|
|||
use rust_mqtt::packet::mqtt_packet::Packet;
|
||||
use rust_mqtt::packet::packet_type::PacketType;
|
||||
use rust_mqtt::encoding::variable_byte_integer::VariableByteIntegerEncoder;
|
||||
use rust_mqtt::encoding::variable_byte_integer::VariableByteIntegerDecoder;
|
||||
|
||||
fn main() {
|
||||
env_logger::builder()
|
||||
|
@ -14,11 +16,22 @@ fn main() {
|
|||
|
||||
let mut txt = *b"abcde";
|
||||
let mut payld = *b"xxxxx";
|
||||
let f = PacketType::Reserved;
|
||||
|
||||
|
||||
let f = PacketType::from(0xA0);
|
||||
let o: u8 = f.into();
|
||||
|
||||
let r = match VariableByteIntegerEncoder::encode(179) {
|
||||
Ok(r) => r,
|
||||
Err(_e) => [0; 4],
|
||||
};
|
||||
log::info!("{:02X?}", r);
|
||||
let d = VariableByteIntegerDecoder::decode(r);
|
||||
log::info!("Enum val: {}", o);
|
||||
let x = Packet::new( l, y, z, p, &mut txt, &mut payld );
|
||||
|
||||
log::info!("Hello world");
|
||||
x.encode();
|
||||
x.get_reason_code();
|
||||
|
||||
}
|
|
@ -1,2 +1,3 @@
|
|||
pub mod mqtt_packet;
|
||||
pub mod packet_type;
|
||||
pub mod packet_type;
|
||||
pub mod packet_builder;
|
20
src/packet/packet_builder.rs
Normal file
20
src/packet/packet_builder.rs
Normal file
|
@ -0,0 +1,20 @@
|
|||
use super::mqtt_packet::Packet;
|
||||
use super::packet_type::PacketType;
|
||||
|
||||
pub struct PacketBuilder<'a> {
|
||||
currentPacket: Packet<'a>,
|
||||
}
|
||||
|
||||
impl<'a> PacketBuilder<'a> {
|
||||
pub fn build(&self) -> &Packet<'a> {
|
||||
return &self.currentPacket;
|
||||
}
|
||||
|
||||
pub fn decode(&self, buffer: &'a mut [u8]) -> &Packet<'a> {
|
||||
return &self.currentPacket;
|
||||
}
|
||||
|
||||
pub fn addPacketType(packet_type: PacketType) {
|
||||
|
||||
}
|
||||
}
|
|
@ -23,9 +23,9 @@ pub enum PacketType {
|
|||
impl From<u8> for PacketType {
|
||||
fn from(orig: u8) -> Self {
|
||||
match orig {
|
||||
0x00 => return PacketType::Reserved,
|
||||
0x10 => return PacketType::Connect,
|
||||
0x20 => return PacketType::Connack,
|
||||
0x00 => return PacketType::Reserved,
|
||||
0x30 => return PacketType::Publish,
|
||||
0x40 => return PacketType::Puback,
|
||||
0x50 => return PacketType::Pubrec,
|
||||
|
@ -44,3 +44,27 @@ impl From<u8> for PacketType {
|
|||
}
|
||||
}
|
||||
|
||||
impl Into<u8> for PacketType {
|
||||
fn into(self) -> u8 {
|
||||
match self {
|
||||
PacketType::Connect => return 0x00,
|
||||
PacketType::Connack => return 0x10,
|
||||
PacketType::Reserved => return 0x20,
|
||||
PacketType::Publish => return 0x30,
|
||||
PacketType::Puback => return 0x40,
|
||||
PacketType::Pubrec => return 0x50,
|
||||
PacketType::Pubrel => return 0x60,
|
||||
PacketType::Pubcomp => return 0x70,
|
||||
PacketType::Subscribe => return 0x80,
|
||||
PacketType::Suback => return 0x90,
|
||||
PacketType::Unsubscribe => return 0xA0,
|
||||
PacketType::Unsuback => return 0xB0,
|
||||
PacketType::Pingreq => return 0xC0,
|
||||
PacketType::Pingresp => return 0xD0,
|
||||
PacketType::Disconnect => return 0xE0,
|
||||
PacketType::Auth => return 0xF0,
|
||||
PacketType::Reserved => return 0x00
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user