ironrdp_core/padding.rs
1//! Padding handling helpers
2//!
3//! For maximum compatibility, messages should be generated with padding set to zero,
4//! and message recipients should not assume padding has any particular
5//! value.
6
7use crate::{ReadCursor, WriteCursor};
8
9/// Writes zeroes using as few `write_u*` calls as possible.
10pub fn write_padding(dst: &mut WriteCursor<'_>, mut n: usize) {
11 loop {
12 match n {
13 0 => break,
14 1 => {
15 dst.write_u8(0);
16 n -= 1;
17 }
18 2..=3 => {
19 dst.write_u16(0);
20 n -= 2;
21 }
22 4..=7 => {
23 dst.write_u32(0);
24 n -= 4;
25 }
26 _ => {
27 dst.write_u64(0);
28 n -= 8;
29 }
30 }
31 }
32}
33
34/// Moves read cursor, ignoring padding bytes.
35#[inline]
36pub fn read_padding(src: &mut ReadCursor<'_>, n: usize) {
37 src.advance(n);
38}