Length-Prefixed Private Frame Codec (daemon/framing.rs)

prime-agent · crates/pa-types/src/daemon/framing.rs · rust · MIT
infra, lang:rust, fw:tokio, tag:codec

A Rust wire codec using an 8-bit length prefix for framing JSON headers and binary payloads over worker sockets. Reuse when building high-performance IPC or daemon client protocols.

// Source: https://github.com/PrimeIntellect-ai/prime-agent | License: MIT | Copyright 2025-2026 Prime Intellect Ltd
// Provided via justclaw.it.com; keep this notice with the code.
//! Length-prefixed private frames: the worker-socket wire codec shared by pa-daemon workers and
//! direct-attach clients (pa-tui/pa-cli) (TS `private-framing.ts`): 8-byte big-endian prefix (u32
//! header length, u32 payload length), JSON header, binary payload.

use anyhow::{anyhow, Context, Result};
use tokio::io::{AsyncRead, AsyncReadExt, AsyncWrite, AsyncWriteExt};

pub const FRAME_PREFIX_BYTES: usize = 8;

#[derive(Debug, Clone, Copy)]
pub struct PrivateFrameLimits {
    pub max_header_bytes: usize,
    pub max_payload_bytes: usize,
}

pub const DEFAULT_PRIVATE_FRAME_LIMITS: PrivateFrameLimits = PrivateF

... (truncated -- full source via MCP)

See the full source, get the GitHub permalink, and search for more like it.

Get a free API key