pub trait DecodeWithLength: Sized {
// Required method
fn decode(src: &[u8], length: usize) -> Result<(Self, usize), DecodeError>;
}Expand description
Trait for decoding SMPP values from a slice with a specified length.
§Implementation
#[derive(Debug, PartialEq, Eq)]
struct Foo {
a: u8,
b: u16,
c: AnyOctetString,
}
impl DecodeWithLength for Foo {
fn decode(src: &[u8], length: usize) -> Result<(Self, usize), DecodeError> {
let index = 0;
let (a, size) = Decode::decode(&src[index..])?;
let index = index + size;
let (b, size) = Decode::decode(&src[index..])?;
let index = index + size;
let (c, size) = AnyOctetString::decode(&src[index..], length - index)?;
let index = index + size;
Ok((Foo { a, b, c }, index))
}
}
// Received over the wire
let length = 8;
let buf = &[0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09];
let expected = Foo {
a: 0x01,
b: 0x0203,
c: AnyOctetString::new([0x04, 0x05, 0x06, 0x07, 0x08]),
};
let (foo, size) = Foo::decode(buf, length).unwrap();
assert_eq!(size, 8);
assert_eq!(foo, expected);
assert_eq!(&buf[size..], &[0x09]);Required Methods§
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.
Implementations on Foreign Types§
Source§impl<T: Decode> DecodeWithLength for Vec<T>
Available on crate feature alloc only.
impl<T: Decode> DecodeWithLength for Vec<T>
Available on crate feature
alloc only.Implementors§
impl DecodeWithLength for Command
Available on crate feature
alloc only.impl DecodeWithLength for AlertNotification
Available on crate feature
alloc only.impl DecodeWithLength for BindReceiverResp
Available on crate feature
alloc only.impl DecodeWithLength for BindTransceiverResp
Available on crate feature
alloc only.impl DecodeWithLength for BindTransmitterResp
Available on crate feature
alloc only.impl DecodeWithLength for BroadcastSm
Available on crate feature
alloc only.impl DecodeWithLength for BroadcastSmResp
Available on crate feature
alloc only.impl DecodeWithLength for CancelBroadcastSm
Available on crate feature
alloc only.impl DecodeWithLength for DataSm
Available on crate feature
alloc only.impl DecodeWithLength for DataSmResp
Available on crate feature
alloc only.impl DecodeWithLength for DeliverSm
Available on crate feature
alloc only.impl DecodeWithLength for DeliverSmResp
Available on crate feature
alloc only.impl DecodeWithLength for QueryBroadcastSm
Available on crate feature
alloc only.impl DecodeWithLength for QueryBroadcastSmResp
Available on crate feature
alloc only.impl DecodeWithLength for ReplaceSm
Available on crate feature
alloc only.impl DecodeWithLength for SubmitMulti
Available on crate feature
alloc only.impl DecodeWithLength for SubmitMultiResp
Available on crate feature
alloc only.impl DecodeWithLength for SubmitSm
Available on crate feature
alloc only.impl DecodeWithLength for SubmitSmResp
Available on crate feature
alloc only.impl DecodeWithLength for AnyOctetString
Available on crate feature
alloc only.impl DecodeWithLength for BroadcastAreaIdentifier
Available on crate feature
alloc only.impl DecodeWithLength for MessagePayload
Available on crate feature
alloc only.impl DecodeWithLength for Subaddress
Available on crate feature
alloc only.impl DecodeWithLength for MsValidity
impl<T: Decode> DecodeWithLength for T
Everything that implements Decode also implements DecodeWithLength by ignoring the length.
impl<const MIN: usize, const MAX: usize> DecodeWithLength for OctetString<MIN, MAX>
Available on crate feature
alloc only.