Trait LtValue

Source
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§

Source

const NAME: &'static str

Required Associated Types§

Required Methods§

Source

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.

Source

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.

Source

fn into_type(&self) -> Self::Type

Retrieve the type of the current value.

Source

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.

Source

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.

Source

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§

Source

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.

Source

fn encode_all( iter: impl Iterator<Item = Self>, buf: &mut [u8], ) -> Result<(), Error>

Encode a collection of LtValue structures into a buffer. Even if the encoding fails, buf may still be modified by previous encoding successes.

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.

Implementors§

Source§

impl LtValue for CodecCapability

Source§

const NAME: &'static str = "Codec Compatability"

Source§

type Type = CodecCapabilityType

Source§

impl LtValue for CodecConfiguration

Source§

const NAME: &'static str = "Codec Compatability"

Source§

type Type = CodecConfigurationType

Source§

impl LtValue for Metadata

Source§

const NAME: &'static str = "Metadata"

Source§

type Type = MetadataType