use bytes::Bytes; use lanspread_proto::{Message, StreamInstallFrame}; #[test] fn file_chunks_encode_raw_bytes() { let bytes = Bytes::from_static(&[0, 1, 2, 255]); let encoded = StreamInstallFrame::FileChunk { bytes: bytes.clone(), } .encode(); assert_eq!(&encoded[..], &[1, 0, 1, 2, 255]); assert_eq!( StreamInstallFrame::decode(encoded), StreamInstallFrame::FileChunk { bytes } ); } #[test] fn control_frames_are_tagged_json() { let frame = StreamInstallFrame::FileBegin { relative_path: "bin/game.exe".to_string(), size: 42, crc32: 0x38B4_88A7, }; let encoded = frame.encode(); assert_eq!(encoded[0], 0); assert_eq!(StreamInstallFrame::decode(encoded), frame); } #[test] fn empty_frames_decode_as_errors() { match StreamInstallFrame::decode(Bytes::new()) { StreamInstallFrame::Error { message } => { assert!(message.contains("empty")); } other => { panic!("expected error frame, got {other:?}"); } } }