pub struct Packet {
pub header: Header,
pub payload: Vec<u8>,
/* private fields */
}
Expand description
The CoAP packet.
Fields§
§header: Header
§payload: Vec<u8>
Implementations§
source§impl Packet
impl Packet
sourcepub const MAX_SIZE: usize = 1_280usize
pub const MAX_SIZE: usize = 1_280usize
Maximum allowed packet size. By default limited to 1280 so that CoAP packets can be sent over TCP or UDP.
sourcepub fn options(&self) -> Iter<'_, u16, LinkedList<Vec<u8>>> ⓘ
pub fn options(&self) -> Iter<'_, u16, LinkedList<Vec<u8>>> ⓘ
Returns an iterator over the options of the packet.
sourcepub fn set_option(&mut self, tp: CoapOption, value: LinkedList<Vec<u8>>)
pub fn set_option(&mut self, tp: CoapOption, value: LinkedList<Vec<u8>>)
Sets an option’s values.
sourcepub fn set_options_as<T: OptionValueType>(
&mut self,
tp: CoapOption,
value: LinkedList<T>
)
pub fn set_options_as<T: OptionValueType>( &mut self, tp: CoapOption, value: LinkedList<T> )
Sets an option’s values using a structured option value format.
sourcepub fn get_option(&self, tp: CoapOption) -> Option<&LinkedList<Vec<u8>>>
pub fn get_option(&self, tp: CoapOption) -> Option<&LinkedList<Vec<u8>>>
Returns an option’s values.
sourcepub fn get_options_as<T: OptionValueType>(
&self,
tp: CoapOption
) -> Option<LinkedList<Result<T, IncompatibleOptionValueFormat>>>
pub fn get_options_as<T: OptionValueType>( &self, tp: CoapOption ) -> Option<LinkedList<Result<T, IncompatibleOptionValueFormat>>>
Returns an option’s values all decoded using the specified structured option value format.
sourcepub fn get_first_option(&self, tp: CoapOption) -> Option<&Vec<u8>>
pub fn get_first_option(&self, tp: CoapOption) -> Option<&Vec<u8>>
Returns an option’s first value as a convenience when only one is expected.
sourcepub fn get_first_option_as<T: OptionValueType>(
&self,
tp: CoapOption
) -> Option<Result<T, IncompatibleOptionValueFormat>>
pub fn get_first_option_as<T: OptionValueType>( &self, tp: CoapOption ) -> Option<Result<T, IncompatibleOptionValueFormat>>
Returns an option’s first value as a convenience when only one is expected.
sourcepub fn add_option(&mut self, tp: CoapOption, value: Vec<u8>)
pub fn add_option(&mut self, tp: CoapOption, value: Vec<u8>)
Adds an option value.
sourcepub fn add_option_as<T: OptionValueType>(&mut self, tp: CoapOption, value: T)
pub fn add_option_as<T: OptionValueType>(&mut self, tp: CoapOption, value: T)
Adds an option value using a structured option value format.
sourcepub fn clear_option(&mut self, tp: CoapOption)
pub fn clear_option(&mut self, tp: CoapOption)
Removes an option.
sourcepub fn clear_all_options(&mut self)
pub fn clear_all_options(&mut self)
Removes all options.
sourcepub fn set_content_format(&mut self, cf: ContentFormat)
pub fn set_content_format(&mut self, cf: ContentFormat)
Sets the content-format.
sourcepub fn get_content_format(&self) -> Option<ContentFormat>
pub fn get_content_format(&self) -> Option<ContentFormat>
Returns the content-format.
sourcepub fn set_observe_value(&mut self, value: u32)
pub fn set_observe_value(&mut self, value: u32)
Sets the value of the observe option.
sourcepub fn get_observe_value(
&self
) -> Option<Result<u32, IncompatibleOptionValueFormat>>
pub fn get_observe_value( &self ) -> Option<Result<u32, IncompatibleOptionValueFormat>>
Returns the value of the observe option.
sourcepub fn from_bytes(buf: &[u8]) -> Result<Packet, MessageError>
pub fn from_bytes(buf: &[u8]) -> Result<Packet, MessageError>
Decodes a byte slice and constructs the equivalent packet.
sourcepub fn to_bytes(&self) -> Result<Vec<u8>, MessageError>
pub fn to_bytes(&self) -> Result<Vec<u8>, MessageError>
Returns a vector of bytes representing the Packet.
sourcepub fn to_bytes_with_limit(&self, limit: usize) -> Result<Vec<u8>, MessageError>
pub fn to_bytes_with_limit(&self, limit: usize) -> Result<Vec<u8>, MessageError>
Returns a vector of bytes representing the Packet, using a custom
limit
instead of Packet::MAX_SIZE
for the message size check.
sourcepub fn to_bytes_unlimited(&self) -> Result<Vec<u8>, MessageError>
pub fn to_bytes_unlimited(&self) -> Result<Vec<u8>, MessageError>
Returns a vector of bytes representing the Packet, skipping the message
size check against Packet::MAX_SIZE
.
Trait Implementations§
source§impl MinimalWritableMessage for Packet
impl MinimalWritableMessage for Packet
§type Code = MessageClass
type Code = MessageClass
Self::set_code()
§type OptionNumber = CoapOption
type OptionNumber = CoapOption
§type AddOptionError = Infallible
type AddOptionError = Infallible
§type SetPayloadError = Infallible
type SetPayloadError = Infallible
§type UnionError = Infallible
type UnionError = Infallible
Code
and OptionNumber
, can be .into()
ed. Read moresource§fn set_code(&mut self, code: Self::Code)
fn set_code(&mut self, code: Self::Code)
source§fn add_option(
&mut self,
option: Self::OptionNumber,
data: &[u8]
) -> Result<(), Self::AddOptionError>
fn add_option( &mut self, option: Self::OptionNumber, data: &[u8] ) -> Result<(), Self::AddOptionError>
source§fn set_payload(&mut self, payload: &[u8]) -> Result<(), Self::SetPayloadError>
fn set_payload(&mut self, payload: &[u8]) -> Result<(), Self::SetPayloadError>
source§fn set_from_message<M>(&mut self, msg: &M) -> Result<(), Self::UnionError>where
M: ReadableMessage + WithSortedOptions,
fn set_from_message<M>(&mut self, msg: &M) -> Result<(), Self::UnionError>where
M: ReadableMessage + WithSortedOptions,
source§fn add_option_str(
&mut self,
number: Self::OptionNumber,
value: &str
) -> Result<(), Self::AddOptionError>
fn add_option_str( &mut self, number: Self::OptionNumber, value: &str ) -> Result<(), Self::AddOptionError>
add_option(self, number, value.as_bytes())
. Read moresource§fn add_option_uint<U>(
&mut self,
number: Self::OptionNumber,
value: U
) -> Result<(), Self::AddOptionError>
fn add_option_uint<U>( &mut self, number: Self::OptionNumber, value: U ) -> Result<(), Self::AddOptionError>
add_option
on a buffer containing the uint encoded value Read moresource§fn convert_code_error(e: <Self::Code as Code>::Error) -> Self::UnionError
fn convert_code_error(e: <Self::Code as Code>::Error) -> Self::UnionError
Self::Code::Error
Read moresource§fn convert_option_number_error(
e: <Self::OptionNumber as OptionNumber>::Error
) -> Self::UnionError
fn convert_option_number_error( e: <Self::OptionNumber as OptionNumber>::Error ) -> Self::UnionError
Self::OptionNumber::Error
Read moresource§fn convert_add_option_error(e: Self::AddOptionError) -> Self::UnionError
fn convert_add_option_error(e: Self::AddOptionError) -> Self::UnionError
Self::AddOptionError
Read moresource§fn convert_set_payload_error(e: Self::SetPayloadError) -> Self::UnionError
fn convert_set_payload_error(e: Self::SetPayloadError) -> Self::UnionError
Self::SetPayloadError
Read moresource§impl MinimalWritableMessage for Packet
impl MinimalWritableMessage for Packet
type Code = MessageClass
type OptionNumber = CoapOption
fn set_code(&mut self, code: Self::Code)
source§fn add_option(&mut self, option: Self::OptionNumber, data: &[u8])
fn add_option(&mut self, option: Self::OptionNumber, data: &[u8])
fn set_payload(&mut self, payload: &[u8])
source§fn set_from_message<M>(&mut self, msg: &M)where
M: ReadableMessage,
fn set_from_message<M>(&mut self, msg: &M)where
M: ReadableMessage,
source§fn add_option_str(&mut self, number: Self::OptionNumber, value: &str)
fn add_option_str(&mut self, number: Self::OptionNumber, value: &str)
add_option(self, number, value.as_bytes())
. Read moresource§fn add_option_uint<U>(&mut self, number: Self::OptionNumber, value: U)where
U: Ux,
fn add_option_uint<U>(&mut self, number: Self::OptionNumber, value: U)where
U: Ux,
add_option
on a buffer containing the uint encoded value Read moresource§impl MutableWritableMessage for Packet
impl MutableWritableMessage for Packet
source§fn available_space(&self) -> usize
fn available_space(&self) -> usize
source§fn payload_mut_with_len(
&mut self,
len: usize
) -> Result<&mut [u8], Self::SetPayloadError>
fn payload_mut_with_len( &mut self, len: usize ) -> Result<&mut [u8], Self::SetPayloadError>
len
bytes of the payload for writing Read moresource§fn truncate(&mut self, length: usize) -> Result<(), Self::SetPayloadError>
fn truncate(&mut self, length: usize) -> Result<(), Self::SetPayloadError>
MinimalWritableMessage::set_payload
, or with a suitable MutableWritableMessage::payload_mut_with_len
call.source§fn mutate_options<F>(&mut self, callback: F)
fn mutate_options<F>(&mut self, callback: F)
source§impl MutableWritableMessage for Packet
impl MutableWritableMessage for Packet
source§fn available_space(&self) -> usize
fn available_space(&self) -> usize
source§fn payload_mut(&mut self) -> &mut [u8] ⓘ
fn payload_mut(&mut self) -> &mut [u8] ⓘ
source§fn payload_mut_with_len(&mut self, len: usize) -> &mut [u8] ⓘ
fn payload_mut_with_len(&mut self, len: usize) -> &mut [u8] ⓘ
len
bytes of the payload for writing Read moresource§fn truncate(&mut self, length: usize)
fn truncate(&mut self, length: usize)
MinimalWritableMessage::set_payload
, or with a suitable MutableWritableMessage::payload_mut_with_len
call.source§fn mutate_options<F>(&mut self, callback: F)
fn mutate_options<F>(&mut self, callback: F)
source§impl ReadableMessage for Packet
impl ReadableMessage for Packet
§type Code = MessageClass
type Code = MessageClass
§type MessageOption<'a> = MessageOption<'a>
type MessageOption<'a> = MessageOption<'a>
§type OptionsIter<'a> = MessageOptionAdapter<'a>
type OptionsIter<'a> = MessageOptionAdapter<'a>
source§fn code(&self) -> Self::Code
fn code(&self) -> Self::Code
source§fn options(&self) -> Self::OptionsIter<'_>
fn options(&self) -> Self::OptionsIter<'_>
source§impl ReadableMessage for Packet
impl ReadableMessage for Packet
§type Code = MessageClass
type Code = MessageClass
Self::code()
§type MessageOption<'a> = MessageOption<'a>
type MessageOption<'a> = MessageOption<'a>
§type OptionsIter<'a> = MessageOptionAdapter<'a>
type OptionsIter<'a> = MessageOptionAdapter<'a>
Self::options()