breakwater_parser/
lib.rs

1// Needed for simple implementation
2#![feature(portable_simd)]
3
4use const_format::formatcp;
5
6#[cfg(target_arch = "x86_64")]
7mod assembler;
8mod framebuffer;
9mod memchr;
10mod original;
11mod refactored;
12
13#[cfg(target_arch = "x86_64")]
14pub use assembler::AssemblerParser;
15pub use framebuffer::{simple::SimpleFrameBuffer, FrameBuffer};
16pub use memchr::MemchrParser;
17pub use original::OriginalParser;
18pub use refactored::RefactoredParser;
19
20pub const HELP_TEXT: &[u8] = formatcp!("\
21Pixelflut server powered by breakwater https://github.com/sbernauer/breakwater
22Available commands:
23HELP: Show this help
24PX x y rrggbb: Color the pixel (x,y) with the given hexadecimal color rrggbb
25{}
26PX x y gg: Color the pixel (x,y) with the hexadecimal color gggggg. Basically this is the same as the other commands, but is a more efficient way of filling white, black or gray areas
27PX x y: Get the color value of the pixel (x,y)
28{}{}SIZE: Get the size of the drawing surface, e.g. `SIZE 1920 1080`
29OFFSET x y: Apply offset (x,y) to all further pixel draws on this connection. This can e.g. be used to pre-calculate an image/animation and simply use the OFFSET command to move it around the screen without the need to re-calculate it
30",
31if cfg!(feature = "alpha") {
32    "PX x y rrggbbaa: Color the pixel (x,y) with the given hexadecimal color rrggbb and a transparency of aa, where ff means draw normally on top of the existing pixel and 00 means fully transparent (no change at all)"
33} else {
34    "PX x y rrggbbaa: Color the pixel (x,y) with the given hexadecimal color rrggbb. The alpha part is discarded for performance reasons, as breakwater was compiled without the alpha feature"
35},
36if cfg!(feature = "binary-set-pixel") {
37    "PBxxyyrgba: Binary version of the PX command. x and y are little-endian 16 bit coordinates, r, g, b and a are a byte each. There is *no* newline after the command.\n"
38} else {
39    ""
40},
41if cfg!(feature = "binary-sync-pixels") {
42    "PXMULTI<startX:16><startY:16><len:32><rgba 1 of (startX, startY)><rgba 2 of (startX + 1, startY)><rgba 3 of (startX + 1, startY)>...<rgba len>: EXPERIMENTAL binary syncing of whole pixel areas. Please note that for performance reasons this will be copied 1:1 to the servers framebuffer. The server will just take the following <len> bytes and memcpy it into the framebuffer, so the alpha channel doesn't matter and you might mess up the screen. This is intended for export-use, especially when syncing or combining multiple Pixelflut screens across multiple servers\n"
43} else {
44    ""
45},
46).as_bytes();
47
48pub const ALT_HELP_TEXT: &[u8] = b"Stop spamming HELP!\n";
49
50pub trait Parser {
51    /// Returns the last byte parsed. The next parsing loop will again contain all data that was not parsed.
52    fn parse(&mut self, buffer: &[u8], response: &mut Vec<u8>) -> usize;
53
54    // Sadly this cant be const (yet?) (https://github.com/rust-lang/rust/issues/71971 and https://github.com/rust-lang/rfcs/pull/2632)
55    fn parser_lookahead(&self) -> usize;
56}