Create all packets

This commit is contained in:
Ondrej Babec
2022-02-18 15:27:18 +01:00
parent 332472f64a
commit 5c814d7501
20 changed files with 1171 additions and 169 deletions

View File

@@ -5,10 +5,14 @@ use core::mem;
#[derive(Debug)]
pub struct EncodedString<'a> {
pub string: &'a str,
pub len: u16
pub len: u16,
}
impl EncodedString<'_> {
pub fn new() -> Self {
Self { string: "", len: 0 }
}
pub fn len(&self) -> u16 {
return self.len + 2;
}
@@ -21,6 +25,10 @@ pub struct BinaryData<'a> {
}
impl BinaryData<'_> {
pub fn new() -> Self {
Self { bin: &[0], len: 0 }
}
pub fn len(&self) -> u16 {
return self.len + 2;
}
@@ -39,6 +47,23 @@ impl StringPair<'_> {
}
}
#[derive(Debug)]
pub struct TopicFilter<'a> {
pub len: u16,
pub filter: EncodedString<'a>,
pub sub_options: u8,
}
impl TopicFilter<'_> {
pub fn new() -> Self {
Self { len: 0, filter: EncodedString::new(), sub_options: 0 }
}
pub fn len(&self) -> u16 {
return self.len + 2;
}
}
#[derive(core::fmt::Debug)]
#[derive(Clone)]
pub enum ParseError {
@@ -142,4 +167,8 @@ impl<'a> BuffReader<'a> {
}
return Ok(StringPair { name: name.unwrap(), value: value.unwrap() });
}
pub fn readMessage(& mut self) -> &'a [u8] {
return &self.buffer[self.position..];
}
}