Struct rusmpp::codec::command_codec::CommandCodec
source · pub struct CommandCodec;Expand description
A codec for encoding and decoding SMPP PDUs.
Only available when the tokio-codec feature is enabled.
§Usage
use futures::{SinkExt, StreamExt};
use rusmpp::{
codec::command_codec::CommandCodec,
commands::{
command::Command,
pdu::Pdu,
types::{command_id::CommandId, command_status::CommandStatus},
},
};
use tokio::net::TcpStream;
use tokio_util::codec::{FramedRead, FramedWrite};
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let stream = TcpStream::connect("34.242.18.250:2775").await?;
let (reader, writer) = stream.into_split();
let mut framed_read = FramedRead::new(reader, CommandCodec {});
let mut framed_write = FramedWrite::new(writer, CommandCodec {});
let enquire_link_command = Command::new(CommandStatus::EsmeRok, 0, Pdu::EnquireLink);
framed_write.send(&enquire_link_command).await?;
while let Some(Ok(command)) = framed_read.next().await {
if let CommandId::EnquireLinkResp = command.command_id() {
break;
}
}
Ok(())
}Trait Implementations§
source§impl Decoder for CommandCodec
impl Decoder for CommandCodec
§type Error = DecodeError
type Error = DecodeError
The type of unrecoverable frame decoding errors. Read more
source§fn decode(
&mut self,
src: &mut BytesMut
) -> Result<Option<Self::Item>, Self::Error>
fn decode( &mut self, src: &mut BytesMut ) -> Result<Option<Self::Item>, Self::Error>
Attempts to decode a frame from the provided buffer of bytes. Read more
Auto Trait Implementations§
impl RefUnwindSafe for CommandCodec
impl Send for CommandCodec
impl Sync for CommandCodec
impl Unpin for CommandCodec
impl UnwindSafe for CommandCodec
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