pub trait Encode: Length {
// Required method
fn encode(&self, dst: &mut BytesMut);
}Available on crate feature
alloc only.Expand description
Trait for encoding SMPP values into a buffer.
§Implementation
struct Foo {
a: u8,
b: u16,
c: u32,
}
impl Length for Foo {
fn length(&self) -> usize {
self.a.length() + self.b.length() + self.c.length()
}
}
impl Encode for Foo {
fn encode(&self, dst: &mut BytesMut) {
self.a.encode(dst);
self.b.encode(dst);
self.c.encode(dst);
}
}
let foo = Foo {
a: 0x01,
b: 0x0203,
c: 0x04050607,
};
let mut buf = BytesMut::with_capacity(1024);
assert!(buf.capacity() >= foo.length());
foo.encode(&mut buf);
let expected = &[0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07];
let buf = buf.split_to(foo.length());
assert_eq!(&buf[..], expected);Required Methods§
Sourcefn encode(&self, dst: &mut BytesMut)
fn encode(&self, dst: &mut BytesMut)
Encode a value into a destination buffer.
Implementors are allowed to panic if the slice is not big enough to hold the encoded value. If dst.capacity() < Length::length