Header

Struct Header 

Source
pub struct Header {
    pub header: u8,
    pub version: [u8; 2],
    pub pkt_type: PktType,
    pub topic_length: u8,
    pub message_length: u16,
    pub padding: u8,
}
Expand description

Header for the pub/sub packet total length 8 bytes.

Fields§

§header: u8

start byte of the packet, default value: 0x0F

§version: [u8; 2]

pub-sub version: two bytes.

§pkt_type: PktType

packet type: PktType

§topic_length: u8

topic length for publishing/subscribing/querying.

§message_length: u16

message length: Max length 16 MB.

§padding: u8

padding/endo of the header: 0x00

Implementations§

Source§

impl Header

Source

pub fn new(pkt_type: PktType, topic_len: u8, message_len: u16) -> Header

creates a new Header with the given data.

use simple_pub_sub_message::header::Header;
use simple_pub_sub_message::PktType;
Header::new(PktType::PUBLISH, 8, 20);
Source

pub fn response_header(&self) -> Result<Header, Error>

returns a Header for the response Msg.

use simple_pub_sub_message::header::Header;
use simple_pub_sub_message::PktType;
let header = Header::new(PktType::PUBLISH, 8, 20);
let response_header = header.response_header();
Source

pub fn bytes(&self) -> [u8; 8]

returns the bytes for Header.

use simple_pub_sub_message::header::Header;
use simple_pub_sub_message::PktType;
let header = Header::new(PktType::PUBLISH, 8, 20);
header.bytes();

Trait Implementations§

Source§

impl Clone for Header

Source§

fn clone(&self) -> Header

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Header

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl PartialEq for Header

Source§

fn eq(&self, other: &Header) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl TryFrom<&[u8]> for Header

Source§

fn try_from(bytes: &[u8]) -> Result<Header, Error>

Parses a Header from a &[u8]

use simple_pub_sub_message::header::Header;
Header::try_from([
       15,    // HEADER_BYTE`
       0, 1,  // `VERSION_BYTE_0`, `VERSION_BYTE_1`
       2,     // `PktType`
       3,     // `TOPIC_LENGTH_BYTE`
       0, 12, // `MESSAGE_LENGTH_BYTE_0`, `MESSAGE_LENGTH_BYTE_1`
       0,     // `PADDING_BYTE`
].as_ref());
Source§

type Error = Error

The type returned in the event of a conversion error.
Source§

impl TryFrom<Vec<u8>> for Header

Source§

fn try_from(bytes: Vec<u8>) -> Result<Header, Error>

Parses a Header from a Vec<u8>.

use simple_pub_sub_message::header::Header;
Header::try_from(vec![
       15,    // `HEADER_BYTE`
       0, 1,  // `VERSION_BYTE_0`, `VERSION_BYTE_1`
       2,     // `PktType`
       3,     // `TOPIC_LENGTH_BYTE`
       0, 12, // `MESSAGE_LENGTH_BYTE_0`, `MESSAGE_LENGTH_BYTE_1`
       0,     // `PADDING_BYTE`
]);
Source§

type Error = Error

The type returned in the event of a conversion error.
Source§

impl StructuralPartialEq for Header

Auto Trait Implementations§

§

impl Freeze for Header

§

impl RefUnwindSafe for Header

§

impl Send for Header

§

impl Sync for Header

§

impl Unpin for Header

§

impl UnwindSafe for Header

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

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

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.