Skip to content

Commit 7cb1ac9

Browse files
elmarcoCBenoit
authored andcommitted
refactor(pdu)!: remove RfxChannelWidth and RfxChannelHeight structs
Signed-off-by: Marc-André Lureau <[email protected]>
1 parent 097cdb6 commit 7cb1ac9

File tree

5 files changed

+14
-54
lines changed

5 files changed

+14
-54
lines changed

crates/ironrdp-pdu/src/codecs/rfx.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,7 @@ pub use self::data_messages::{
1515
ContextPdu, EntropyAlgorithm, FrameBeginPdu, FrameEndPdu, OperatingMode, Quant, RegionPdu, RfxRectangle, Tile,
1616
TileSetPdu,
1717
};
18-
pub use self::header_messages::{
19-
ChannelsPdu, CodecVersionsPdu, RfxChannel, RfxChannelHeight, RfxChannelWidth, SyncPdu,
20-
};
18+
pub use self::header_messages::{ChannelsPdu, CodecVersionsPdu, RfxChannel, SyncPdu};
2119

2220
const CODEC_ID: u8 = 1;
2321
const CHANNEL_ID_FOR_CONTEXT: u8 = 0xFF;

crates/ironrdp-pdu/src/codecs/rfx/header_messages.rs

+6-44
Original file line numberDiff line numberDiff line change
@@ -155,46 +155,8 @@ impl<'de> Decode<'de> for ChannelsPdu {
155155
/// [2.2.2.1.3]: https://learn.microsoft.com/pt-br/openspecs/windows_protocols/ms-rdprfx/4060f07e-9d73-454d-841e-131a93aca675
156156
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
157157
pub struct RfxChannel {
158-
pub width: RfxChannelWidth,
159-
pub height: RfxChannelHeight,
160-
}
161-
162-
/// A 16-bit, signed integer within the range of 1 to 4096
163-
#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
164-
#[repr(transparent)]
165-
pub struct RfxChannelWidth(i16);
166-
167-
impl RfxChannelWidth {
168-
pub fn new(value: i16) -> Self {
169-
Self(value)
170-
}
171-
172-
pub fn as_u16(self) -> u16 {
173-
u16::try_from(self.0).expect("integer within the range of 1 to 4096")
174-
}
175-
176-
pub fn get(self) -> i16 {
177-
self.0
178-
}
179-
}
180-
181-
/// A 16-bit, signed integer within the range of 1 to 2048
182-
#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
183-
#[repr(transparent)]
184-
pub struct RfxChannelHeight(i16);
185-
186-
impl RfxChannelHeight {
187-
pub fn new(value: i16) -> Self {
188-
Self(value)
189-
}
190-
191-
pub fn as_u16(self) -> u16 {
192-
u16::try_from(self.0).expect("integer within the range of 1 to 2048")
193-
}
194-
195-
pub fn get(self) -> i16 {
196-
self.0
197-
}
158+
pub width: i16,
159+
pub height: i16,
198160
}
199161

200162
impl RfxChannel {
@@ -208,8 +170,8 @@ impl Encode for RfxChannel {
208170
ensure_fixed_part_size!(in: dst);
209171

210172
dst.write_u8(CHANNEL_ID);
211-
dst.write_i16(self.width.get());
212-
dst.write_i16(self.height.get());
173+
dst.write_i16(self.width);
174+
dst.write_i16(self.height);
213175

214176
Ok(())
215177
}
@@ -232,8 +194,8 @@ impl<'de> Decode<'de> for RfxChannel {
232194
return Err(invalid_field_err!("channelId", "Invalid channel ID"));
233195
}
234196

235-
let width = RfxChannelWidth::new(src.read_i16());
236-
let height = RfxChannelHeight::new(src.read_i16());
197+
let width = src.read_i16();
198+
let height = src.read_i16();
237199

238200
Ok(Self { width, height })
239201
}

crates/ironrdp-server/src/encoder/rfx.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use ironrdp_graphics::rfx_encode_component;
44
use ironrdp_graphics::rlgr::RlgrError;
55
use ironrdp_pdu::codecs::rfx::{
66
self, Block, ChannelsPdu, CodecChannel, CodecVersionsPdu, FrameBeginPdu, FrameEndPdu, OperatingMode, Quant,
7-
RegionPdu, RfxChannel, RfxChannelHeight, RfxChannelWidth, SyncPdu, TileSetPdu,
7+
RegionPdu, RfxChannel, SyncPdu, TileSetPdu,
88
};
99
use ironrdp_pdu::rdp::capability_sets::EntropyBits;
1010
use ironrdp_pdu::WriteCursor;
@@ -42,8 +42,8 @@ impl RfxEncoder {
4242
Block::CodecChannel(CodecChannel::Context(context)).encode(&mut cursor)?;
4343

4444
let channels = ChannelsPdu(vec![RfxChannel {
45-
width: RfxChannelWidth::new(cast_length!("width", width)?),
46-
height: RfxChannelHeight::new(cast_length!("height", height)?),
45+
width: cast_length!("width", width)?,
46+
height: cast_length!("height", height)?,
4747
}]);
4848
Block::Channels(channels).encode(&mut cursor)?;
4949

crates/ironrdp-session/src/rfx.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,8 @@ impl DecodingContext {
108108
destination: &InclusiveRectangle,
109109
) -> SessionResult<(FrameId, InclusiveRectangle)> {
110110
let channel = self.channels.0.first().unwrap();
111-
let width = channel.width.as_u16();
112-
let height = channel.height.as_u16();
111+
let width = channel.width.try_into().map_err(|_| general_err!("invalid width"))?;
112+
let height = channel.height.try_into().map_err(|_| general_err!("invalid height"))?;
113113
let entropy_algorithm = self.context.entropy_algorithm;
114114

115115
let region: rfx::Block<'_> = decode_cursor(input).map_err(|e| custom_err!("decode region", e))?;

crates/ironrdp-testsuite-core/tests/pdu/rfx.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -253,8 +253,8 @@ const FRAME_END_PDU: Block<'_> = Block::CodecChannel(CodecChannel::FrameEnd(Fram
253253

254254
lazy_static::lazy_static! {
255255
static ref CHANNELS_PDU: Block<'static> = Block::Channels(ChannelsPdu(vec![
256-
RfxChannel { width: RfxChannelWidth::new(64), height: RfxChannelHeight::new(64) },
257-
RfxChannel { width: RfxChannelWidth::new(32), height: RfxChannelHeight::new(32) }
256+
RfxChannel { width: 64, height: 64 },
257+
RfxChannel { width: 32, height: 32 }
258258
]));
259259
static ref REGION_PDU: Block<'static> = Block::CodecChannel(CodecChannel::Region(RegionPdu {
260260
rectangles: vec![

0 commit comments

Comments
 (0)