amebazii

Macro write_data

Source
macro_rules! write_data {
    ($writer:expr, $key:expr, $len:literal) => { ... };
}
Expand description

Writes data to a stream.

This macro writes the key to the stream if it is present. If the key is None, the macro writes padding instead, ensuring the correct number of bytes is always written.

§Parameters:

  • $writer: The writer where the key (or padding) should be written. Must implement the std::io::Write trait.
  • $key: The key to write. This can be Some([u8; N]) where N is the length of the key, or None to indicate that the key is missing.
  • $len: The length of the key (or the padding) in bytes. This will determine how many bytes to write if the key is absent.

§Example:

let mut buffer = Vec::new();
let key: Option<[u8; 10]> = Some([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]);
write_data!(buffer, key, 10);