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