pub struct Tlv {
pub tag: u16,
pub length: u16,
pub value: Vec<u8>,
}Fields§
§tag: u16§length: u16§value: Vec<u8>Implementations§
Source§impl Tlv
impl Tlv
pub fn new(tag: u16, value: Vec<u8>) -> Self
Sourcepub fn new_from_name(name: &str, value: Vec<u8>) -> Self
pub fn new_from_name(name: &str, value: Vec<u8>) -> Self
Convenience: create a TLV using a string name for the tag
Sourcepub fn new_u8(tag: u16, val: u8) -> Self
pub fn new_u8(tag: u16, val: u8) -> Self
Examples found in repository?
examples/alert_notification.rs (line 19)
5fn main() {
6 println!("=== SMPP Alert Notification Example ===");
7
8 // 1. Create Alert Notification
9 let mut alert = AlertNotification::new(
10 200, // Sequence number
11 "source_addr".to_string(),
12 "esme_addr".to_string(),
13 )
14 .with_source_addr(Ton::International, Npi::Isdn, "123".to_string())
15 .with_esme_addr(Ton::National, Npi::Telex, "456".to_string());
16
17 // 2. Add optional TLV (e.g., ms_availability_status)
18 // Tag 0x0402 is ms_availability_status
19 let tlv = Tlv::new_u8(0x0402, 1); // 1 = Available
20 alert.add_tlv(tlv);
21
22 println!("Alert Notification: {:?}", alert);
23
24 // 3. Encode
25 let mut buf = Vec::new();
26 alert.encode(&mut buf).unwrap();
27 println!("Encoded {} bytes", buf.len());
28}pub fn new_u8_from_name(name: &str, val: u8) -> Self
pub fn new_u16(tag: u16, val: u16) -> Self
pub fn new_u16_from_name(name: &str, val: u16) -> Self
pub fn new_string(tag: u16, val: &str) -> Self
pub fn new_payload(tag: u16, val: Vec<u8>) -> Self
pub fn encode(&self, writer: &mut impl Write) -> Result<(), PduError>
pub fn decode(cursor: &mut Cursor<&[u8]>) -> Result<Option<Self>, PduError>
pub fn value_as_u8(&self) -> Result<u8, PduError>
pub fn value_as_u16(&self) -> Result<u16, PduError>
pub fn value_as_string(&self) -> Result<String, PduError>
Trait Implementations§
impl StructuralPartialEq for Tlv
Auto Trait Implementations§
impl Freeze for Tlv
impl RefUnwindSafe for Tlv
impl Send for Tlv
impl Sync for Tlv
impl Unpin for Tlv
impl UnwindSafe for Tlv
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more