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 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 MinimalWritableMessage for Packet
impl MinimalWritableMessage for Packet
Source§type Code = MessageClass
type Code = MessageClass
Self::set_code()
Source§type OptionNumber = CoapOption
type OptionNumber = CoapOption
Source§type AddOptionError = Infallible
type AddOptionError = Infallible
Source§type SetPayloadError = Infallible
type SetPayloadError = Infallible
Source§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 with_static_type_annotation(
&mut self,
) -> Option<RefMutWithStaticType<'_, Self>>
fn with_static_type_annotation( &mut self, ) -> Option<RefMutWithStaticType<'_, Self>>
Source§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 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 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 ReadableMessage for Packet
impl ReadableMessage for Packet
Source§type Code = MessageClass
type Code = MessageClass
Source§type MessageOption<'a> = MessageOption<'a>
type MessageOption<'a> = MessageOption<'a>
Source§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
Source§type Code = MessageClass
type Code = MessageClass
Self::code()
Source§type MessageOption<'a> = MessageOption<'a>
type MessageOption<'a> = MessageOption<'a>
Source§type OptionsIter<'a> = MessageOptionAdapter<'a>
type OptionsIter<'a> = MessageOptionAdapter<'a>
Self::options()