diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index e4e4a18..b4b4b21 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -123,17 +123,17 @@ jobs: uses: actions-rs/cargo@v1 with: command: test - args: --no-default-features + args: --no-default-features --all-targets - name: Test with all features turned on uses: actions-rs/cargo@v1 with: command: test - args: --all-features - - name: Test vnc features + args: --all-features --all-targets + - name: Test vnc feature uses: actions-rs/cargo@v1 with: command: test - args: --no-default-features --features vnc + args: --no-default-features --features vnc --all-targets run_build: name: Build for ${{ matrix.target }} diff --git a/breakwater-parser/src/original.rs b/breakwater-parser/src/original.rs index e35b38a..a55f8da 100644 --- a/breakwater-parser/src/original.rs +++ b/breakwater-parser/src/original.rs @@ -10,6 +10,7 @@ use crate::Parser; pub const PARSER_LOOKAHEAD: usize = "PX 1234 1234 rrggbbaa\n".len(); // Longest possible command pub(crate) const PX_PATTERN: u64 = string_to_number(b"PX \0\0\0\0\0"); +pub(crate) const PB_PATTERN: u64 = string_to_number(b"PB\0\0\0\0\0\0"); pub(crate) const OFFSET_PATTERN: u64 = string_to_number(b"OFFSET \0\0"); pub(crate) const SIZE_PATTERN: u64 = string_to_number(b"SIZE\0\0\0\0"); pub(crate) const HELP_PATTERN: u64 = string_to_number(b"HELP\0\0\0\0"); @@ -140,6 +141,21 @@ impl Parser for OriginalParser { continue; } } + // In case the feature is disabled this if should be optimized away, as "cfg!" should be a constant expression. + } else if cfg!(feature = "binary-commands") + && current_command & 0x0000_ffff == PB_PATTERN + { + let command_bytes = + unsafe { (buffer.as_ptr().add(i + 2) as *const u64).read_unaligned() }; + + let x = u16::from_le((command_bytes) as u16); + let y = u16::from_le((command_bytes >> 16) as u16); + let rgba = u32::from_le((command_bytes >> 32) as u32); + + self.fb.set(x as usize, y as usize, rgba & 0x00ff_ffff); + + i += 10; + continue; } else if current_command & 0x00ff_ffff_ffff_ffff == OFFSET_PATTERN { i += 7; diff --git a/breakwater/src/tests.rs b/breakwater/src/tests.rs index 42fc8dd..fef2976 100644 --- a/breakwater/src/tests.rs +++ b/breakwater/src/tests.rs @@ -136,6 +136,44 @@ async fn test_setting_pixel( assert_eq!(expected, stream.get_output()); } +#[cfg(feature = "binary-commands")] +#[rstest] +// No newline in between needed +#[case("PB\0\0\0\0\0\0\0\0PX 0 0\n", "PX 0 0 000000\n")] +#[case("PB\0\0\0\01234PX 0 0\n", "PX 0 0 313233\n")] +#[case("PB\0\0\0\0\0\0\0\0PB\0\0\0\01234PX 0 0\n", "PX 0 0 313233\n")] +#[case( + "PB\0\0\0\0\0\0\0\0PX 0 0\nPB\0\0\0\01234PX 0 0\n", + "PX 0 0 000000\nPX 0 0 313233\n" +)] +#[case("PB \0*\0____PX 32 42\n", "PX 32 42 5f5f5f\n")] +#[tokio::test] +async fn test_binary_commands( + #[case] input: &str, + #[case] expected: &str, + ip: IpAddr, + fb: Arc, + statistics_channel: ( + mpsc::Sender, + mpsc::Receiver, + ), +) { + let mut stream = MockTcpStream::from_input(input); + handle_connection( + &mut stream, + ip, + fb, + statistics_channel.0, + DEFAULT_NETWORK_BUFFER_SIZE, + page_size::get(), + None, + ) + .await + .unwrap(); + + assert_eq!(expected, stream.get_output()); +} + #[rstest] #[case("PX 0 0 aaaaaa\n")] #[case("PX 0 0 aa\n")] @@ -180,8 +218,8 @@ async fn test_safe( #[case(479, 361, 721, 391)] #[case(500, 500, 0, 0)] #[case(500, 500, 300, 400)] -#[case(fb().get_width(), fb().get_height(), 0, 0)] -#[case(fb().get_width() - 1, fb().get_height() - 1, 1, 1)] +// Yes, this exceeds the framebuffer size +#[case(10, 10, fb().get_width(), fb().get_height())] #[tokio::test] async fn test_drawing_rect( #[case] width: usize,