Skip to main content

dmsg_write

Function dmsg_write 

Source
pub fn dmsg_write(
    mbuf: &mut Mbuf,
    msg_id: MsgId,
    ty: DmsgType,
    flags: u8,
    same_dc: bool,
    aes_key_payload: Option<&[u8]>,
    plen: u32,
) -> Result<(), DnodeError>
Expand description

Encode a DNODE header into the writable region of mbuf.

aes_key_payload, when Some, is written as the inline data field; this is how the crypto handshake transports the RSA-wrapped AES key. When None, a single-byte 'd' placeholder is emitted.

flags is taken verbatim (the encryption bit must be set by the caller, alongside any compression bit).

The encoder writes the entire header as a single contiguous region; if mbuf lacks the necessary capacity, DnodeError::OutOfSpace is returned.

ยงExamples

use dynomite::io::mbuf::MbufPool;
use dynomite::proto::dnode::{dmsg_write, DmsgType};

let pool = MbufPool::default();
let mut buf = pool.get();
dmsg_write(
    &mut buf,
    /* msg_id */ 1,
    DmsgType::Req,
    /* flags */ 0,
    /* same_dc */ true,
    /* aes_key_payload */ None,
    /* plen */ 0,
)
.unwrap();
assert!(buf.readable().starts_with(b"   $2014$ 1 3 0"));