diff --git a/crates/ericrfb/src/proto.rs b/crates/ericrfb/src/proto.rs index cb1076b..b4282d5 100644 --- a/crates/ericrfb/src/proto.rs +++ b/crates/ericrfb/src/proto.rs @@ -135,15 +135,11 @@ fn decode_modified_utf8(data: &[u8]) -> Result { // Two-byte sequence: 110xxxxx 10xxxxxx 12 | 13 => { if i + 1 >= data.len() { - return Err(ProtoError::InvalidUtf8( - "truncated 2-byte sequence".into(), - )); + return Err(ProtoError::InvalidUtf8("truncated 2-byte sequence".into())); } let b2 = data[i + 1]; if b2 & 0xC0 != 0x80 { - return Err(ProtoError::InvalidUtf8( - "invalid continuation byte".into(), - )); + return Err(ProtoError::InvalidUtf8("invalid continuation byte".into())); } let cp = ((b as u32 & 0x1F) << 6) | (b2 as u32 & 0x3F); out.push(char::from_u32(cp).unwrap_or('\u{FFFD}')); @@ -152,19 +148,14 @@ fn decode_modified_utf8(data: &[u8]) -> Result { // Three-byte sequence: 1110xxxx 10xxxxxx 10xxxxxx 14 => { if i + 2 >= data.len() { - return Err(ProtoError::InvalidUtf8( - "truncated 3-byte sequence".into(), - )); + return Err(ProtoError::InvalidUtf8("truncated 3-byte sequence".into())); } let b2 = data[i + 1]; let b3 = data[i + 2]; if (b2 & 0xC0 != 0x80) || (b3 & 0xC0 != 0x80) { - return Err(ProtoError::InvalidUtf8( - "invalid continuation byte".into(), - )); + return Err(ProtoError::InvalidUtf8("invalid continuation byte".into())); } - let cp = - ((b as u32 & 0x0F) << 12) | ((b2 as u32 & 0x3F) << 6) | (b3 as u32 & 0x3F); + let cp = ((b as u32 & 0x0F) << 12) | ((b2 as u32 & 0x3F) << 6) | (b3 as u32 & 0x3F); out.push(char::from_u32(cp).unwrap_or('\u{FFFD}')); i += 3; } @@ -340,7 +331,11 @@ mod tests { let mut buf = Vec::new(); write_varint(&mut buf, val).unwrap(); let mut c = Cursor::new(&buf); - assert_eq!(read_varint(&mut c).unwrap(), val, "roundtrip failed for {val}"); + assert_eq!( + read_varint(&mut c).unwrap(), + val, + "roundtrip failed for {val}" + ); } } @@ -384,7 +379,16 @@ mod tests { let mut c = Cursor::new(&data[..]); let hdr = RectHeader::read_from(&mut c).unwrap(); - assert_eq!(hdr, RectHeader { x: 10, y: 20, w: 640, h: 480, encoding: 7 }); + assert_eq!( + hdr, + RectHeader { + x: 10, + y: 20, + w: 640, + h: 480, + encoding: 7 + } + ); } #[test]