[−][src]Struct jnet::coap::Message
CoAP (version 1) message
Methods
impl<B, P> Message<B, P> where
B: AsSlice<Element = u8>,
[src]
B: AsSlice<Element = u8>,
pub fn get_version(&self) -> u8
[src]
Returns the Version field of the header
As per RFC 7252 this always returns 1
pub fn get_type(&self) -> Type
[src]
Returns the Type field of the header
pub fn get_token_length(&self) -> u8
[src]
Returns the Token Length (TKL) field of the header
As per RFC 7252 this always returns a value in the range 0..=8
pub fn get_code(&self) -> Code
[src]
Returns the Code field of the header
pub fn get_message_id(&self) -> u16
[src]
Returns the Message ID field of the header
pub fn token(&self) -> &[u8]
[src]
View into the Token field of the header
pub fn as_bytes(&self) -> &[u8]
[src]
Returns the byte representation of this message
pub fn len(&self) -> u16
[src]
Returns the length (header + data) of the CoAP message
ⓘImportant traits for Options<'a>pub fn options(&self) -> Options
[src]
Returns an iterator over the options of this message
impl<B, P> Message<B, P> where
B: AsMutSlice<Element = u8>,
[src]
B: AsMutSlice<Element = u8>,
pub fn set_code<C>(&mut self, code: C) where
C: Into<Code>,
[src]
C: Into<Code>,
Sets the Code field of the header
pub fn set_message_id(&mut self, id: u16)
[src]
Sets the Message ID field of the header
pub fn set_type(&mut self, ty: Type)
[src]
Sets the Type field of the header
pub fn token_mut(&mut self) -> &mut [u8]
[src]
Mutable view into the Token field
impl<B> Message<B, Set> where
B: AsSlice<Element = u8>,
[src]
B: AsSlice<Element = u8>,
pub fn parse(bytes: B) -> Result<Self, B>
[src]
Parses bytes into a CoAP message
pub fn payload(&self) -> &[u8]
[src]
View into the payload
impl<B> Message<B, Set> where
B: AsMutSlice<Element = u8>,
[src]
B: AsMutSlice<Element = u8>,
pub fn payload_mut(&mut self) -> &mut [u8]
[src]
Mutable view into the payload
impl<B> Message<B, Unset> where
B: AsMutSlice<Element = u8>,
[src]
B: AsMutSlice<Element = u8>,
pub fn new(buffer: B, token_length: u8) -> Self
[src]
Transforms the given buffer into a CoAP message
This constructor sets the following header fields
- Version = 1
- Token Length = token_length
NOTE The CoAP message will span the whole buffer.
Panics
This constructor panics if
token_length
is NOT in the range0..=8
.- The buffer is not large enough to contain the CoAP header
pub fn add_option(&mut self, number: OptionNumber, value: &[u8])
[src]
Adds an option to this message
HEADS UP This method will cause the first bytes of the payload to be lost
Panics
This method panics
- if
number
is smaller than the highest option number already contained in the message - if there's no space in the message to add the option
pub fn clear_options(&mut self)
[src]
Removes all the options this message has
impl<B> Message<B, Unset> where
B: AsMutSlice<Element = u8> + Truncate<u16>,
[src]
B: AsMutSlice<Element = u8> + Truncate<u16>,
pub fn set_payload(self, data: &[u8]) -> Message<B>
[src]
Fills the payload with the given data and adjusts the length of the CoAP message
pub fn no_payload(self) -> Message<B>
[src]
Finishing constructing this message by leaving the payload empty and truncating the message
Trait Implementations
Auto Trait Implementations
impl<BUFFER, PAYLOAD> Unpin for Message<BUFFER, PAYLOAD> where
BUFFER: Unpin,
PAYLOAD: Unpin,
BUFFER: Unpin,
PAYLOAD: Unpin,
impl<BUFFER, PAYLOAD> Send for Message<BUFFER, PAYLOAD> where
BUFFER: Send,
PAYLOAD: Send,
BUFFER: Send,
PAYLOAD: Send,
impl<BUFFER, PAYLOAD> Sync for Message<BUFFER, PAYLOAD> where
BUFFER: Sync,
PAYLOAD: Sync,
BUFFER: Sync,
PAYLOAD: Sync,
Blanket Implementations
impl<T> From<T> for T
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Same<T> for T
[src]
type Output = T
Should always be Self