mirror of
https://github.com/Devolutions/IronRDP.git
synced 2025-07-08 01:55:01 +00:00
refactor(pdu): drop PduParsing
Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
This commit is contained in:
parent
c046e5396b
commit
4da364367e
7 changed files with 2 additions and 72 deletions
|
@ -7,7 +7,6 @@ use glutin::event::{ElementState, Event, WindowEvent};
|
|||
use ironrdp::pdu::input::fast_path::{FastPathInput, FastPathInputEvent, KeyboardFlags};
|
||||
use ironrdp::pdu::input::mouse::PointerFlags;
|
||||
use ironrdp::pdu::input::MousePdu;
|
||||
use ironrdp::pdu::PduParsing;
|
||||
use ironrdp::session::ErasedWriter;
|
||||
use tokio::sync::Mutex;
|
||||
|
||||
|
|
|
@ -1,41 +1,10 @@
|
|||
//! Legacy compat layer based on the old PduParsing trait
|
||||
|
||||
use std::borrow::Cow;
|
||||
|
||||
use ironrdp_pdu::write_buf::WriteBuf;
|
||||
use ironrdp_pdu::{decode, encode_vec, rdp, x224, PduDecode, PduEncode, PduParsing};
|
||||
use ironrdp_pdu::{decode, encode_vec, rdp, PduDecode, PduEncode};
|
||||
|
||||
use crate::{ConnectorError, ConnectorErrorExt as _, ConnectorResult};
|
||||
|
||||
pub fn encode_x224_packet<T>(x224_msg: &T, buf: &mut WriteBuf) -> ConnectorResult<usize>
|
||||
where
|
||||
T: PduParsing,
|
||||
ConnectorError: From<T::Error>,
|
||||
{
|
||||
let x224_msg_len = x224_msg.buffer_length();
|
||||
let mut x224_msg_buf = Vec::with_capacity(x224_msg_len);
|
||||
|
||||
x224_msg.to_buffer(&mut x224_msg_buf)?;
|
||||
|
||||
let pdu = x224::X224Data {
|
||||
data: Cow::Owned(x224_msg_buf),
|
||||
};
|
||||
|
||||
let written = ironrdp_pdu::encode_buf(&pdu, buf).map_err(ConnectorError::pdu)?;
|
||||
|
||||
Ok(written)
|
||||
}
|
||||
|
||||
pub fn decode_x224_packet<T>(src: &[u8]) -> ConnectorResult<T>
|
||||
where
|
||||
T: PduParsing,
|
||||
ConnectorError: From<T::Error>,
|
||||
{
|
||||
let x224_payload = ironrdp_pdu::decode::<x224::X224Data<'_>>(src).map_err(ConnectorError::pdu)?;
|
||||
let x224_msg = T::from_buffer(x224_payload.data.as_ref())?;
|
||||
Ok(x224_msg)
|
||||
}
|
||||
|
||||
pub fn encode_send_data_request<T>(
|
||||
initiator_id: u16,
|
||||
channel_id: u16,
|
||||
|
|
|
@ -229,8 +229,6 @@ struct DynamicChannelCtx<'a> {
|
|||
}
|
||||
|
||||
fn decode_dvc_message(user_data: &[u8]) -> PduResult<DynamicChannelCtx<'_>> {
|
||||
use ironrdp_pdu::{custom_err, PduParsing as _};
|
||||
|
||||
let mut user_data = user_data;
|
||||
let user_data_len = user_data.len();
|
||||
|
||||
|
|
|
@ -15,7 +15,7 @@ use pdu::dvc::{CreateRequestPdu, DataFirstPdu, DataPdu};
|
|||
use pdu::gcc::ChannelName;
|
||||
use pdu::rdp::vc;
|
||||
use pdu::write_buf::WriteBuf;
|
||||
use pdu::{cast_length, custom_err, encode_vec, invalid_message_err, other_err, PduEncode, PduParsing};
|
||||
use pdu::{cast_length, custom_err, encode_vec, invalid_message_err, other_err, PduEncode};
|
||||
use pdu::{dvc, PduResult};
|
||||
|
||||
use crate::{CompleteData, DvcMessages, DvcProcessor};
|
||||
|
|
|
@ -10,7 +10,6 @@ use glutin::dpi::PhysicalSize;
|
|||
use ironrdp::pdu::dvc::gfx;
|
||||
use ironrdp::pdu::dvc::gfx::{Codec1Type, ServerPdu};
|
||||
use ironrdp::pdu::geometry::Rectangle;
|
||||
use ironrdp::pdu::PduParsing;
|
||||
use thiserror::Error;
|
||||
|
||||
use crate::surface::{DataBuffer, SurfaceDecoders, Surfaces};
|
||||
|
|
|
@ -390,40 +390,6 @@ mod legacy {
|
|||
|
||||
use crate::{PduEncode, PduResult, WriteCursor};
|
||||
|
||||
pub const MAX_PDU_SIZE: usize = 100 * 1024; // 100 kB
|
||||
|
||||
pub trait PduParsing {
|
||||
type Error;
|
||||
|
||||
fn from_buffer(stream: impl std::io::Read) -> Result<Self, Self::Error>
|
||||
where
|
||||
Self: Sized;
|
||||
fn to_buffer(&self, stream: impl std::io::Write) -> Result<(), Self::Error>;
|
||||
fn buffer_length(&self) -> usize;
|
||||
}
|
||||
|
||||
/// Blanket implementation for references to types implementing PduParsing. Only encoding is supported.
|
||||
///
|
||||
/// This helps removing a few copies.
|
||||
impl<T: PduParsing> PduParsing for &T {
|
||||
type Error = T::Error;
|
||||
|
||||
fn from_buffer(_: impl std::io::Read) -> Result<Self, Self::Error>
|
||||
where
|
||||
Self: Sized,
|
||||
{
|
||||
panic!("Can’t return a reference to a local value")
|
||||
}
|
||||
|
||||
fn to_buffer(&self, stream: impl std::io::Write) -> Result<(), Self::Error> {
|
||||
T::to_buffer(self, stream)
|
||||
}
|
||||
|
||||
fn buffer_length(&self) -> usize {
|
||||
T::buffer_length(self)
|
||||
}
|
||||
}
|
||||
|
||||
pub trait PduBufferParsing<'a>: Sized {
|
||||
type Error;
|
||||
|
||||
|
|
|
@ -14,7 +14,6 @@ use glutin::dpi::PhysicalSize;
|
|||
use glutin::event::{Event, WindowEvent};
|
||||
use glutin::event_loop::ControlFlow;
|
||||
use ironrdp::pdu::dvc::gfx::{GraphicsPipelineError, ServerPdu};
|
||||
use ironrdp::pdu::PduParsing;
|
||||
use ironrdp_glutin_renderer::renderer::Renderer;
|
||||
|
||||
pub type Error = Box<dyn std::error::Error + Send + Sync + 'static>;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue