dbus_message_parser/encode/
encoder.rs

1use bytes::{BufMut, BytesMut};
2#[cfg(target_family = "unix")]
3use std::os::unix::io::RawFd;
4
5pub struct Encoder {
6    pub(crate) buf: BytesMut,
7    #[cfg(target_family = "unix")]
8    pub(crate) fds: Vec<RawFd>,
9}
10
11impl Encoder {
12    /// This is a helper function to add the algin to the buffer.
13    pub(crate) fn algin(&mut self, a: usize) {
14        let remain = self.buf.len() % a;
15        if remain != 0 {
16            let padding_length = a - remain;
17            self.buf.reserve(padding_length);
18
19            for _ in 0..padding_length {
20                self.buf.put_u8(0);
21            }
22        }
23    }
24
25    pub fn new() -> Encoder {
26        Encoder {
27            buf: BytesMut::new(),
28            #[cfg(target_family = "unix")]
29            fds: Vec::new(),
30        }
31    }
32}