pub struct BindRequest {
pub sequence_number: u32,
pub mode: BindMode,
pub system_id: String,
pub password: String,
pub system_type: String,
pub interface_version: u8,
pub addr_ton: Ton,
pub addr_npi: Npi,
pub address_range: String,
}Expand description
Represents a Bind Request PDU (Receiver, Transmitter, or Transceiver).
This PDU is used to initiate a session with the SMSC.
Fields§
§sequence_number: u32§mode: BindMode§system_id: String§password: String§system_type: String§interface_version: u8§addr_ton: Ton§addr_npi: Npi§address_range: StringImplementations§
Source§impl BindRequest
impl BindRequest
Sourcepub fn new(
sequence_number: u32,
mode: BindMode,
system_id: String,
password: String,
) -> Self
pub fn new( sequence_number: u32, mode: BindMode, system_id: String, password: String, ) -> Self
Create a new Bind Request with defaults.
§Examples
use smpp_codec::pdus::BindRequest;
use smpp_codec::common::BindMode;
let sequence_number: u32 = 1;
let bind_req = BindRequest::new(
sequence_number,
BindMode::Transceiver,
"system_id".to_string(),
"password".to_string(),
);Examples found in repository?
examples/bind_transceiver.rs (lines 8-13)
4fn main() {
5 println!("=== SMPP Bind Transceiver Example ===");
6
7 // 1. Create a BindTransceiver Request
8 let bind_req = BindRequest::new(
9 1, // Sequence Number
10 BindMode::Transceiver,
11 "my_system_id".to_string(),
12 "password".to_string(),
13 )
14 .with_address_range(Ton::International, Npi::Isdn, "12345".to_string());
15
16 println!("Created PDU: {:?}", bind_req);
17
18 // 2. Encode into bytes
19 let mut buffer = Vec::new();
20 match bind_req.encode(&mut buffer) {
21 Ok(_) => {
22 println!("Encoded successfully! {} bytes", buffer.len());
23 print!("Hex encoded: ");
24 for byte in &buffer {
25 print!("{:02X} ", byte);
26 }
27 println!();
28 }
29 Err(e) => {
30 eprintln!("Failed to encode: {:?}", e);
31 }
32 }
33}Sourcepub fn with_address_range(self, ton: Ton, npi: Npi, range: String) -> Self
pub fn with_address_range(self, ton: Ton, npi: Npi, range: String) -> Self
Examples found in repository?
examples/bind_transceiver.rs (line 14)
4fn main() {
5 println!("=== SMPP Bind Transceiver Example ===");
6
7 // 1. Create a BindTransceiver Request
8 let bind_req = BindRequest::new(
9 1, // Sequence Number
10 BindMode::Transceiver,
11 "my_system_id".to_string(),
12 "password".to_string(),
13 )
14 .with_address_range(Ton::International, Npi::Isdn, "12345".to_string());
15
16 println!("Created PDU: {:?}", bind_req);
17
18 // 2. Encode into bytes
19 let mut buffer = Vec::new();
20 match bind_req.encode(&mut buffer) {
21 Ok(_) => {
22 println!("Encoded successfully! {} bytes", buffer.len());
23 print!("Hex encoded: ");
24 for byte in &buffer {
25 print!("{:02X} ", byte);
26 }
27 println!();
28 }
29 Err(e) => {
30 eprintln!("Failed to encode: {:?}", e);
31 }
32 }
33}Sourcepub fn encode(&self, writer: &mut impl Write) -> Result<(), PduError>
pub fn encode(&self, writer: &mut impl Write) -> Result<(), PduError>
Encode the struct into raw bytes for the network.
§Errors
Returns a PduError if:
system_idexceeds 16 characters.passwordexceeds 9 characters.system_typeexceeds 13 characters.address_rangeexceeds 41 characters.- An I/O error occurs while writing.
§Examples
let mut buffer = Vec::new();
bind_req.encode(&mut buffer).expect("Encoding failed");Examples found in repository?
examples/bind_transceiver.rs (line 20)
4fn main() {
5 println!("=== SMPP Bind Transceiver Example ===");
6
7 // 1. Create a BindTransceiver Request
8 let bind_req = BindRequest::new(
9 1, // Sequence Number
10 BindMode::Transceiver,
11 "my_system_id".to_string(),
12 "password".to_string(),
13 )
14 .with_address_range(Ton::International, Npi::Isdn, "12345".to_string());
15
16 println!("Created PDU: {:?}", bind_req);
17
18 // 2. Encode into bytes
19 let mut buffer = Vec::new();
20 match bind_req.encode(&mut buffer) {
21 Ok(_) => {
22 println!("Encoded successfully! {} bytes", buffer.len());
23 print!("Hex encoded: ");
24 for byte in &buffer {
25 print!("{:02X} ", byte);
26 }
27 println!();
28 }
29 Err(e) => {
30 eprintln!("Failed to encode: {:?}", e);
31 }
32 }
33}Sourcepub fn decode(buffer: &[u8]) -> Result<Self, PduError>
pub fn decode(buffer: &[u8]) -> Result<Self, PduError>
Decode raw bytes from the network into the struct.
§Errors
Returns a PduError if:
- The buffer is too short to contain a valid header.
- The command ID does not correspond to a Bind Request.
- The buffer data is malformed.
§Examples
let decoded = BindRequest::decode(&buffer).expect("Decoding failed");
assert_eq!(decoded.system_id, "id");Trait Implementations§
Source§impl Clone for BindRequest
impl Clone for BindRequest
Source§fn clone(&self) -> BindRequest
fn clone(&self) -> BindRequest
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreAuto Trait Implementations§
impl Freeze for BindRequest
impl RefUnwindSafe for BindRequest
impl Send for BindRequest
impl Sync for BindRequest
impl Unpin for BindRequest
impl UnwindSafe for BindRequest
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