Function tfc::parse_byte_command [−][src]
pub fn parse_byte_command(
buf: &[u8]
) -> Result<(Command, usize), ParseByteCommandError>
Parse a sequence of bytes to create a Command
.
The first byte in the buffer must be a CommandCode
. This
identifies the command and its arguments. Following the command identifier
is a sequence of bytes that encode the arguments of the command.
Key
and MouseButton
are single bytes. For integer
arguments (used for moving the mouse and scrolling), 16-bit signed
big-endian integers are used.
Returns the command and the number of bytes that were read from the buffer.
Arguments
buf
- The byte buffer to read from.
Examples
let bytes = &[ tfc::CommandCode::MouseMoveRel as u8, 255, 214, 0, 64, tfc::CommandCode::KeyClick as u8, tfc::Key::K as u8 ]; let (command, len) = tfc::parse_byte_command(bytes).unwrap(); assert_eq!(len, 5); assert_eq!(command, tfc::Command::MouseMoveRel(-42, 64)); let bytes = &bytes[len..]; let (command, len) = tfc::parse_byte_command(bytes).unwrap(); assert_eq!(len, 2); assert_eq!(command, tfc::Command::KeyClick(tfc::Key::K));