@@ -7,8 +7,8 @@ use ironrdp_core::{
77 decode_cursor, ensure_fixed_part_size, ensure_size, invalid_field_err, Decode , DecodeError , DecodeResult , Encode ,
88 EncodeResult , InvalidFieldErr as _, ReadCursor , WriteCursor ,
99} ;
10- use num_derive:: { FromPrimitive , ToPrimitive } ;
11- use num_traits:: { FromPrimitive as _, ToPrimitive as _ } ;
10+ use num_derive:: FromPrimitive ;
11+ use num_traits:: FromPrimitive as _;
1212
1313use super :: bitmap:: BitmapUpdateData ;
1414use super :: pointer:: PointerUpdateData ;
@@ -136,15 +136,15 @@ impl Encode for FastPathUpdatePdu<'_> {
136136 }
137137
138138 let mut header = 0u8 ;
139- header. set_bits ( 0 ..4 , self . update_code . to_u8 ( ) . unwrap ( ) ) ;
140- header. set_bits ( 4 ..6 , self . fragmentation . to_u8 ( ) . unwrap ( ) ) ;
139+ header. set_bits ( 0 ..4 , self . update_code . as_u8 ( ) ) ;
140+ header. set_bits ( 4 ..6 , self . fragmentation . as_u8 ( ) ) ;
141141
142142 dst. write_u8 ( header) ;
143143
144144 if self . compression_flags . is_some ( ) {
145145 header. set_bits ( 6 ..8 , Compression :: COMPRESSION_USED . bits ( ) ) ;
146- let compression_flags_with_type = self . compression_flags . map ( |f| f . bits ( ) ) . unwrap_or ( 0 )
147- | self . compression_type . and_then ( |f| f. to_u8 ( ) ) . unwrap_or ( 0 ) ;
146+ let compression_flags_with_type =
147+ self . compression_flags . map ( |f| f. bits ( ) ) . unwrap_or ( 0 ) | self . compression_type . map_or ( 0 , |f| f . as_u8 ( ) ) ;
148148 dst. write_u8 ( compression_flags_with_type) ;
149149 }
150150
@@ -312,7 +312,8 @@ impl Encode for FastPathUpdate<'_> {
312312 }
313313}
314314
315- #[ derive( Debug , Copy , Clone , PartialEq , Eq , FromPrimitive , ToPrimitive ) ]
315+ #[ repr( u8 ) ]
316+ #[ derive( Debug , Copy , Clone , PartialEq , Eq , FromPrimitive ) ]
316317pub enum UpdateCode {
317318 Orders = 0x0 ,
318319 Bitmap = 0x1 ,
@@ -328,6 +329,16 @@ pub enum UpdateCode {
328329 LargePointer = 0xc ,
329330}
330331
332+ impl UpdateCode {
333+ #[ expect(
334+ clippy:: as_conversions,
335+ reason = "guarantees discriminant layout, and as is the only way to cast enum -> primitive"
336+ ) ]
337+ pub fn as_u8 ( self ) -> u8 {
338+ self as u8
339+ }
340+ }
341+
331342impl From < & FastPathUpdate < ' _ > > for UpdateCode {
332343 fn from ( update : & FastPathUpdate < ' _ > ) -> Self {
333344 match update {
@@ -346,14 +357,25 @@ impl From<&FastPathUpdate<'_>> for UpdateCode {
346357 }
347358}
348359
349- #[ derive( Debug , Copy , Clone , PartialEq , Eq , FromPrimitive , ToPrimitive ) ]
360+ #[ repr( u8 ) ]
361+ #[ derive( Debug , Copy , Clone , PartialEq , Eq , FromPrimitive ) ]
350362pub enum Fragmentation {
351363 Single = 0x0 ,
352364 Last = 0x1 ,
353365 First = 0x2 ,
354366 Next = 0x3 ,
355367}
356368
369+ impl Fragmentation {
370+ #[ expect(
371+ clippy:: as_conversions,
372+ reason = "guarantees discriminant layout, and as is the only way to cast enum -> primitive"
373+ ) ]
374+ pub fn as_u8 ( self ) -> u8 {
375+ self as u8
376+ }
377+ }
378+
357379bitflags ! {
358380 #[ derive( Debug , Clone , Copy , PartialEq , Eq , PartialOrd , Ord , Hash ) ]
359381 pub struct EncryptionFlags : u8 {
0 commit comments