pub struct Frame<'a> {
pub opcode: u8,
pub payload: &'a [u8],
}Expand description
One parsed HID frame.
Holds a borrow into the underlying buffer. Lifetimes are tied to
the buffer that was parsed, so a Frame is cheap to pass around without
copies.
Fields§
§opcode: u8First byte of the report: a CommandOpcode from the host or a
ResponseStatus from the token, depending on direction.
payload: &'a [u8]Payload bytes (len bytes from the parsed report).
Implementations§
Source§impl<'a> Frame<'a>
impl<'a> Frame<'a>
Sourcepub fn parse(buf: &'a [u8]) -> Result<Self, FrameParseError>
pub fn parse(buf: &'a [u8]) -> Result<Self, FrameParseError>
Parse a HID report into a Frame.
Returns a frame borrowing into buf. The payload slice has the
length declared in the header (len), not the report size. Padding
bytes after the payload are not validated: they are ignored
according to the protocol contract.
§Errors
See FrameParseError.
Sourcepub fn write(
opcode: u8,
payload: &[u8],
out: &mut [u8],
) -> Result<(), FrameBuildError>
pub fn write( opcode: u8, payload: &[u8], out: &mut [u8], ) -> Result<(), FrameBuildError>
Build a HID report from an opcode and a payload.
Writes into out (must be exactly HID_REPORT_SIZE long). All
bytes past the payload are zeroed.
§Errors
Returns FrameBuildError::WrongOutputSize if out is not
HID_REPORT_SIZE bytes, or
FrameBuildError::PayloadTooLarge if payload.len() exceeds
MAX_PAYLOAD_SIZE.
Sourcepub fn to_report(
opcode: u8,
payload: &[u8],
) -> Result<[u8; 128], FrameBuildError>
pub fn to_report( opcode: u8, payload: &[u8], ) -> Result<[u8; 128], FrameBuildError>
Convenience wrapper around Frame::write that returns the report
by value on the stack. Useful for callers that just want a buffer
to hand to embassy-usb or to the OS HID layer.
§Errors
See Frame::write.