Skip to main content

Module ipc_codec

Module ipc_codec 

Source
Expand description

Low-level helpers for encoding/decoding IpcMessage payloads.

§Overview

IPC messages carry a fixed 240-byte payload. This module provides safe, bounds-checked helpers to pack and unpack structured data into that payload without external allocators or serde.

§Layers

  1. Scalar helpers : put_u16/get_u16, put_u32/get_u32, put_u64/get_u64.
  2. Variable-length helpers : put_bytes/get_bytes, put_str/get_str.
  3. Fixed-size helpers : encode_fixed/decode_fixed for repr(C) zerocopy structs.
  4. InlineBlobHeader : minimal framing for inline variable-length data.

All helpers are bounds-checked: they return Option instead of panicking.

§Payload layout conventions

  • Fixed messages: the entire payload[0..48] (or a prefix) is a repr(C) struct. Use encode_fixed/decode_fixed.
  • Variable messages: the fixed-size part goes first (e.g. flags + u64s), followed by an InlineBlobHeader (4 bytes) and the inline data. Use the put/get helpers for the fixed part, then InlineBlobHeader::write for the variable tail.

§Safety

All functions are pure safe-Rust: no unsafe required at this layer. The zerocopy traits used by payload structs are derived safely.

§Examples

§Fixed-size message

use strat9_abi::data::IpcMessage;
use strat9_abi::ipc_codec::{encode_fixed, decode_fixed};

// Encode a struct into a message
#[derive(FromBytes, IntoBytes)]
#[repr(C)]
struct OpenReq { flags: u32, mode: u32 }

let msg = encode_fixed(0x01, &OpenReq { flags: 0x02, mode: 0o644 });

// Decode it back
let req: &OpenReq = decode_fixed(&msg).unwrap();
assert_eq!(req.flags, 0x02);

§Variable-length message

use strat9_abi::ipc_codec::{put_u32, InlineBlobHeader};

let mut msg = IpcMessage::new(0x03);
put_u32(&mut msg.payload, 0, 0o755).unwrap(); // mode
InlineBlobHeader::write(&mut msg.payload, 4, 0, b"/dev/null").unwrap();

Structs§

InlineBlobHeader
Minimal framing header for variable-length data embedded in an IPC payload.

Constants§

PAYLOAD_CAPACITY
Capacity of the IpcMessage.payload field (240 bytes).

Functions§

decode_fixed
Try to decode a fixed-size repr(C) struct from an IpcMessage payload.
encode_fixed
Encode a fixed-size repr(C) struct as an IpcMessage.
encode_fixed_reply
Encode a fixed-size reply targeting sender.
get_bytes
Return a reference to payload[off..off + len].
get_i32
Read an i32 at offset off (little-endian), or None if out of bounds.
get_str
Decode a UTF-8 string of len bytes from payload[off..].
get_u16
Read a u16 at offset off (little-endian), or None if out of bounds.
get_u32
Read a u32 at offset off (little-endian), or None if out of bounds.
get_u64
Read a u64 at offset off (little-endian), or None if out of bounds.
put_bytes
Copy src into payload[off..off + src.len()].
put_i32
Write an i32 at offset off (little-endian).
put_str
Encode a UTF-8 string into payload[off..].
put_u16
Write a u16 at offset off (little-endian).
put_u32
Write a u32 at offset off (little-endian).
put_u64
Write a u64 at offset off (little-endian).