style: apply rustfmt to proto.rs
All checks were successful
CI / fmt (push) Successful in 32s
CI / check (push) Successful in 55s
CI / clippy (push) Successful in 59s

Fixes CI fmt check failure — rustfmt wants multi-line assert_eq! for
long struct literals and the varint roundtrip assertion.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-05-06 13:59:54 +03:00
parent c4e3df5a44
commit 07db90094d

View File

@@ -135,15 +135,11 @@ fn decode_modified_utf8(data: &[u8]) -> Result<String> {
// Two-byte sequence: 110xxxxx 10xxxxxx // Two-byte sequence: 110xxxxx 10xxxxxx
12 | 13 => { 12 | 13 => {
if i + 1 >= data.len() { if i + 1 >= data.len() {
return Err(ProtoError::InvalidUtf8( return Err(ProtoError::InvalidUtf8("truncated 2-byte sequence".into()));
"truncated 2-byte sequence".into(),
));
} }
let b2 = data[i + 1]; let b2 = data[i + 1];
if b2 & 0xC0 != 0x80 { if b2 & 0xC0 != 0x80 {
return Err(ProtoError::InvalidUtf8( return Err(ProtoError::InvalidUtf8("invalid continuation byte".into()));
"invalid continuation byte".into(),
));
} }
let cp = ((b as u32 & 0x1F) << 6) | (b2 as u32 & 0x3F); let cp = ((b as u32 & 0x1F) << 6) | (b2 as u32 & 0x3F);
out.push(char::from_u32(cp).unwrap_or('\u{FFFD}')); out.push(char::from_u32(cp).unwrap_or('\u{FFFD}'));
@@ -152,19 +148,14 @@ fn decode_modified_utf8(data: &[u8]) -> Result<String> {
// Three-byte sequence: 1110xxxx 10xxxxxx 10xxxxxx // Three-byte sequence: 1110xxxx 10xxxxxx 10xxxxxx
14 => { 14 => {
if i + 2 >= data.len() { if i + 2 >= data.len() {
return Err(ProtoError::InvalidUtf8( return Err(ProtoError::InvalidUtf8("truncated 3-byte sequence".into()));
"truncated 3-byte sequence".into(),
));
} }
let b2 = data[i + 1]; let b2 = data[i + 1];
let b3 = data[i + 2]; let b3 = data[i + 2];
if (b2 & 0xC0 != 0x80) || (b3 & 0xC0 != 0x80) { if (b2 & 0xC0 != 0x80) || (b3 & 0xC0 != 0x80) {
return Err(ProtoError::InvalidUtf8( return Err(ProtoError::InvalidUtf8("invalid continuation byte".into()));
"invalid continuation byte".into(),
));
} }
let cp = let cp = ((b as u32 & 0x0F) << 12) | ((b2 as u32 & 0x3F) << 6) | (b3 as u32 & 0x3F);
((b as u32 & 0x0F) << 12) | ((b2 as u32 & 0x3F) << 6) | (b3 as u32 & 0x3F);
out.push(char::from_u32(cp).unwrap_or('\u{FFFD}')); out.push(char::from_u32(cp).unwrap_or('\u{FFFD}'));
i += 3; i += 3;
} }
@@ -340,7 +331,11 @@ mod tests {
let mut buf = Vec::new(); let mut buf = Vec::new();
write_varint(&mut buf, val).unwrap(); write_varint(&mut buf, val).unwrap();
let mut c = Cursor::new(&buf); 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 mut c = Cursor::new(&data[..]);
let hdr = RectHeader::read_from(&mut c).unwrap(); 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] #[test]