mirror of
https://github.com/Devolutions/IronRDP.git
synced 2025-08-04 15:18:17 +00:00
refactor(pdu): convert FrameAcknowledgePdu to PduEncode/Decode
Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
This commit is contained in:
parent
e88c9af70d
commit
2f955f16c3
2 changed files with 31 additions and 13 deletions
|
@ -65,7 +65,7 @@ pub fn pdu_decode(data: &[u8]) {
|
|||
let _ = decode::<surface_commands::BitmapDataHeader>(data);
|
||||
|
||||
let _ = codecs::rfx::Headers::from_buffer(data);
|
||||
let _ = codecs::rfx::FrameAcknowledgePdu::from_buffer(data);
|
||||
let _ = decode::<codecs::rfx::FrameAcknowledgePdu>(data);
|
||||
let _ = codecs::rfx::ContextPdu::from_buffer(data);
|
||||
let _ = codecs::rfx::FrameBeginPdu::from_buffer(data);
|
||||
let _ = codecs::rfx::FrameEndPdu::from_buffer(data);
|
||||
|
|
|
@ -8,7 +8,10 @@ use num_derive::{FromPrimitive, ToPrimitive};
|
|||
use num_traits::{FromPrimitive as _, ToPrimitive as _};
|
||||
use thiserror::Error;
|
||||
|
||||
use crate::{PduBufferParsing, PduParsing};
|
||||
use crate::{
|
||||
cursor::{ReadCursor, WriteCursor},
|
||||
PduBufferParsing, PduDecode, PduEncode, PduResult,
|
||||
};
|
||||
|
||||
#[rustfmt::skip]
|
||||
pub use self::data_messages::{
|
||||
|
@ -168,26 +171,41 @@ pub struct FrameAcknowledgePdu {
|
|||
pub frame_id: u32,
|
||||
}
|
||||
|
||||
impl PduParsing for FrameAcknowledgePdu {
|
||||
type Error = io::Error;
|
||||
impl FrameAcknowledgePdu {
|
||||
const NAME: &'static str = "FrameAcknowledgePdu";
|
||||
|
||||
fn from_buffer(mut stream: impl io::Read) -> Result<Self, Self::Error> {
|
||||
let frame_id = stream.read_u32::<LittleEndian>()?;
|
||||
const FIXED_PART_SIZE: usize = 4 /* frameId */;
|
||||
}
|
||||
|
||||
Ok(Self { frame_id })
|
||||
}
|
||||
|
||||
fn to_buffer(&self, mut stream: impl io::Write) -> Result<(), Self::Error> {
|
||||
stream.write_u32::<LittleEndian>(self.frame_id)?;
|
||||
impl PduEncode for FrameAcknowledgePdu {
|
||||
fn encode(&self, dst: &mut WriteCursor<'_>) -> PduResult<()> {
|
||||
ensure_fixed_part_size!(in: dst);
|
||||
|
||||
dst.write_u32(self.frame_id);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn buffer_length(&self) -> usize {
|
||||
4
|
||||
fn name(&self) -> &'static str {
|
||||
Self::NAME
|
||||
}
|
||||
|
||||
fn size(&self) -> usize {
|
||||
Self::FIXED_PART_SIZE
|
||||
}
|
||||
}
|
||||
|
||||
impl<'de> PduDecode<'de> for FrameAcknowledgePdu {
|
||||
fn decode(src: &mut ReadCursor<'de>) -> PduResult<Self> {
|
||||
ensure_fixed_part_size!(in: src);
|
||||
|
||||
let frame_id = src.read_u32();
|
||||
|
||||
Ok(Self { frame_id })
|
||||
}
|
||||
}
|
||||
|
||||
impl_pdu_parsing!(FrameAcknowledgePdu);
|
||||
|
||||
#[derive(Debug, Copy, Clone, PartialEq, Eq, FromPrimitive, ToPrimitive)]
|
||||
#[repr(u16)]
|
||||
pub enum BlockType {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue