diff --git a/crates/ironrdp-pdu/src/lib.rs b/crates/ironrdp-pdu/src/lib.rs index f12ce053e..fd23622b9 100644 --- a/crates/ironrdp-pdu/src/lib.rs +++ b/crates/ironrdp-pdu/src/lib.rs @@ -141,6 +141,20 @@ pub trait PduEncode { assert_obj_safe!(PduEncode); +impl PduEncode for Box { + fn encode(&self, dst: &mut WriteCursor<'_>) -> PduResult<()> { + self.as_ref().encode(dst) + } + + fn name(&self) -> &'static str { + self.as_ref().name() + } + + fn size(&self) -> usize { + self.as_ref().size() + } +} + /// Encodes the given PDU in-place into the provided buffer and returns the number of bytes written. pub fn encode(pdu: &T, dst: &mut [u8]) -> PduResult { let mut cursor = WriteCursor::new(dst); @@ -148,21 +162,11 @@ pub fn encode(pdu: &T, dst: &mut [u8]) -> PduResult { Ok(cursor.pos()) } -pub fn encode_box(pdu: Box, dst: &mut [u8]) -> PduResult { - let mut cursor = WriteCursor::new(dst); - encode_cursor_box(pdu, &mut cursor)?; - Ok(cursor.pos()) -} - /// Encodes the given PDU in-place using the provided `WriteCursor`. pub fn encode_cursor(pdu: &T, dst: &mut WriteCursor<'_>) -> PduResult<()> { pdu.encode(dst) } -pub fn encode_cursor_box(pdu: Box, dst: &mut WriteCursor<'_>) -> PduResult<()> { - pdu.encode(dst) -} - /// Same as `encode` but resizes the buffer when it is too small to fit the PDU. #[cfg(feature = "alloc")] pub fn encode_buf(pdu: &T, buf: &mut WriteBuf) -> PduResult { @@ -174,15 +178,6 @@ pub fn encode_buf(pdu: &T, buf: &mut WriteBuf) -> PduResult Ok(written) } -pub fn encode_buf_box(pdu: Box, buf: &mut WriteBuf) -> PduResult { - let pdu_size = pdu.size(); - let dst = buf.unfilled_to(pdu_size); - let written = encode_box(pdu, dst)?; - debug_assert_eq!(written, pdu_size); - buf.advance(written); - Ok(written) -} - /// Same as `encode` but allocates and returns a new buffer each time. /// /// This is a convenience function, but it’s not very ressource efficient. diff --git a/crates/ironrdp-svc/src/lib.rs b/crates/ironrdp-svc/src/lib.rs index 6802b340e..42e30c9ac 100644 --- a/crates/ironrdp-svc/src/lib.rs +++ b/crates/ironrdp-svc/src/lib.rs @@ -10,7 +10,7 @@ use bitflags::bitflags; use core::any::{Any, TypeId}; use core::fmt; use pdu::cursor::WriteCursor; -use pdu::{encode_buf, encode_buf_box, PduEncode}; +use pdu::{encode_buf, PduEncode}; use ironrdp_pdu::gcc::{ChannelName, ChannelOptions}; use ironrdp_pdu::write_buf::WriteBuf; @@ -77,7 +77,7 @@ pub fn chunkify(pdus: Vec>, max_chunk_len: usize) -> PduResul /// [[ ChannelPDUHeader | 1600 bytes of PDU data ] [ ChannelPDUHeader | 1600 bytes of PDU data ] [ ChannelPDUHeader | 800 bytes of PDU data ]] fn chunkify_one(pdu: Box, max_chunk_len: usize) -> PduResult> { let mut encoded_pdu = WriteBuf::new(); // TODO(perf): reuse this buffer using `clear` and `filled` as appropriate - encode_buf_box(pdu, &mut encoded_pdu)?; + encode_buf(&pdu, &mut encoded_pdu)?; let mut chunks = Vec::new();