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
- Scalar helpers :
put_u16/get_u16,put_u32/get_u32,put_u64/get_u64. - Variable-length helpers :
put_bytes/get_bytes,put_str/get_str. - Fixed-size helpers :
encode_fixed/decode_fixedforrepr(C)zerocopy structs. 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 arepr(C)struct. Useencode_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, thenInlineBlobHeader::writefor 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§
- Inline
Blob Header - Minimal framing header for variable-length data embedded in an IPC payload.
Constants§
- PAYLOAD_
CAPACITY - Capacity of the
IpcMessage.payloadfield (240 bytes).
Functions§
- decode_
fixed - Try to decode a fixed-size
repr(C)struct from anIpcMessagepayload. - encode_
fixed - Encode a fixed-size
repr(C)struct as anIpcMessage. - encode_
fixed_ reply - Encode a fixed-size reply targeting
sender. - get_
bytes - Return a reference to
payload[off..off + len]. - get_i32
- Read an
i32at offsetoff(little-endian), orNoneif out of bounds. - get_str
- Decode a UTF-8 string of
lenbytes frompayload[off..]. - get_u16
- Read a
u16at offsetoff(little-endian), orNoneif out of bounds. - get_u32
- Read a
u32at offsetoff(little-endian), orNoneif out of bounds. - get_u64
- Read a
u64at offsetoff(little-endian), orNoneif out of bounds. - put_
bytes - Copy
srcintopayload[off..off + src.len()]. - put_i32
- Write an
i32at offsetoff(little-endian). - put_str
- Encode a UTF-8 string into
payload[off..]. - put_u16
- Write a
u16at offsetoff(little-endian). - put_u32
- Write a
u32at offsetoff(little-endian). - put_u64
- Write a
u64at offsetoff(little-endian).