pub trait LtValue: Sized {
type Type: Into<u8> + Copy + Debug;
const NAME: &'static str;
// Required methods
fn type_from_octet(x: u8) -> Option<Self::Type>;
fn length_range_from_type(ty: Self::Type) -> RangeInclusive<u8>;
fn into_type(&self) -> Self::Type;
fn value_encoded_len(&self) -> u8;
fn decode_value(ty: &Self::Type, buf: &[u8]) -> Result<Self, Error>;
fn encode_value(&self, buf: &mut [u8]) -> Result<(), Error>;
// Provided methods
fn decode_all(buf: &[u8]) -> (Vec<Result<Self, Error<Self::Type>>>, usize) { ... }
fn encode_all(
iter: impl Iterator<Item = Self>,
buf: &mut [u8],
) -> Result<(), Error> { ... }
}
Expand description
Implement Ltv when a collection of types is represented in the Bluetooth specifications as a length-type-value structure. They should have an associated type which can be retrieved from a type byte.
Required Associated Constants§
Required Associated Types§
Required Methods§
Sourcefn type_from_octet(x: u8) -> Option<Self::Type>
fn type_from_octet(x: u8) -> Option<Self::Type>
Given a type octet, return the associated Type if it is possible. Returns None if the value is unrecognized.
Sourcefn length_range_from_type(ty: Self::Type) -> RangeInclusive<u8>
fn length_range_from_type(ty: Self::Type) -> RangeInclusive<u8>
Returns length bounds for the type indicated, including the type byte. Note that the assigned numbers from the Bluetooth SIG include the type byte in their Length specifications.
Sourcefn value_encoded_len(&self) -> u8
fn value_encoded_len(&self) -> u8
The length of the encoded value, without the length and type byte. This cannot be 255 in practice, as the length byte is only one octet long.
Sourcefn decode_value(ty: &Self::Type, buf: &[u8]) -> Result<Self, Error>
fn decode_value(ty: &Self::Type, buf: &[u8]) -> Result<Self, Error>
Decodes the value from a buffer, which does not include the type or
length bytes. The buf
slice length is exactly what was specified
for this value in the encoded source.
Sourcefn encode_value(&self, buf: &mut [u8]) -> Result<(), Error>
fn encode_value(&self, buf: &mut [u8]) -> Result<(), Error>
Encodes a value into buf
, which is verified to be the correct length
as indicated by LtValue::value_encoded_len.
Provided Methods§
Sourcefn decode_all(buf: &[u8]) -> (Vec<Result<Self, Error<Self::Type>>>, usize)
fn decode_all(buf: &[u8]) -> (Vec<Result<Self, Error<Self::Type>>>, usize)
Decode a collection of LtValue structures that are present in a buffer. If it is possible to continue decoding after encountering an error, does so and includes the error. If an unrecoverable error occurs, does not consume the final item and the last element in the result is the error.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.