2026-04-24 12:32:24 -06:00
|
|
|
//! Archived protocol message types.
|
2026-04-20 23:38:02 -06:00
|
|
|
|
2026-04-24 12:32:24 -06:00
|
|
|
use alloc::{string::String, vec::Vec};
|
2026-04-20 23:38:02 -06:00
|
|
|
use rkyv::{Archive, Deserialize, Serialize};
|
|
|
|
|
|
2026-04-24 12:32:24 -06:00
|
|
|
/// The three protocol packet types.
|
|
|
|
|
#[repr(u8)]
|
|
|
|
|
#[derive(Archive, Serialize, Deserialize, Debug, Clone, Copy, PartialEq, Eq)]
|
|
|
|
|
pub enum PacketType {
|
|
|
|
|
/// Downwards procedure invocation.
|
|
|
|
|
Call = 0x01,
|
|
|
|
|
/// Returned or continuing hook traffic.
|
|
|
|
|
Data = 0x02,
|
|
|
|
|
/// Upstream protocol failure tied to a hook.
|
|
|
|
|
Fault = 0xFF,
|
|
|
|
|
}
|
2026-04-20 23:38:02 -06:00
|
|
|
|
2026-04-24 12:32:24 -06:00
|
|
|
/// Header fields used for routing and hook attribution.
|
|
|
|
|
#[derive(Archive, Serialize, Deserialize, Debug, Clone, PartialEq, Eq)]
|
2026-04-20 23:38:02 -06:00
|
|
|
pub struct PacketHeader {
|
2026-04-24 12:32:24 -06:00
|
|
|
/// Packet semantics discriminator.
|
2026-04-20 23:38:02 -06:00
|
|
|
pub packet_type: PacketType,
|
2026-04-24 12:32:24 -06:00
|
|
|
/// Sending endpoint path.
|
|
|
|
|
pub src_path: Vec<String>,
|
|
|
|
|
/// Destination endpoint path.
|
|
|
|
|
pub dst_path: Vec<String>,
|
|
|
|
|
/// Optional target leaf for calls.
|
|
|
|
|
pub dst_leaf: Option<String>,
|
|
|
|
|
/// Optional hook identifier for `Data` and `Fault` packets.
|
|
|
|
|
pub hook_id: Option<u64>,
|
2026-04-20 23:38:02 -06:00
|
|
|
}
|
|
|
|
|
|
2026-04-24 12:32:24 -06:00
|
|
|
/// Hook declaration embedded inside a call.
|
2026-04-20 23:38:02 -06:00
|
|
|
#[derive(Archive, Serialize, Deserialize, Debug, Clone, PartialEq, Eq)]
|
2026-04-24 12:32:24 -06:00
|
|
|
pub struct HookTarget {
|
|
|
|
|
/// Hook identifier scoped to `return_path`.
|
|
|
|
|
pub hook_id: u64,
|
|
|
|
|
/// Path of the endpoint that hosts the hook.
|
|
|
|
|
pub return_path: Vec<String>,
|
2026-04-20 23:38:02 -06:00
|
|
|
}
|
|
|
|
|
|
2026-04-24 12:32:24 -06:00
|
|
|
/// Downwards call payload.
|
2026-04-20 23:38:02 -06:00
|
|
|
#[derive(Archive, Serialize, Deserialize, Debug, Clone, PartialEq, Eq)]
|
2026-04-24 12:32:24 -06:00
|
|
|
pub struct CallMessage {
|
|
|
|
|
/// Canonical procedure contract identifier.
|
|
|
|
|
pub procedure_id: String,
|
|
|
|
|
/// Opaque application bytes.
|
2026-04-20 23:38:02 -06:00
|
|
|
pub data: Vec<u8>,
|
2026-04-24 12:32:24 -06:00
|
|
|
/// Optional response hook declaration.
|
|
|
|
|
pub response_hook: Option<HookTarget>,
|
2026-04-20 23:38:02 -06:00
|
|
|
}
|
|
|
|
|
|
2026-04-24 12:32:24 -06:00
|
|
|
/// Hook data payload.
|
2026-04-20 23:38:02 -06:00
|
|
|
#[derive(Archive, Serialize, Deserialize, Debug, Clone, PartialEq, Eq)]
|
2026-04-24 12:32:24 -06:00
|
|
|
pub struct DataMessage {
|
|
|
|
|
/// Procedure contract anchored to the originating call.
|
|
|
|
|
pub procedure_id: String,
|
|
|
|
|
/// Opaque application bytes.
|
2026-04-20 23:38:02 -06:00
|
|
|
pub data: Vec<u8>,
|
2026-04-24 12:32:24 -06:00
|
|
|
/// Indicates that this sender is done with the hook.
|
|
|
|
|
pub end_hook: bool,
|
2026-04-20 23:38:02 -06:00
|
|
|
}
|
|
|
|
|
|
2026-04-24 12:32:24 -06:00
|
|
|
/// Protocol fault payload.
|
2026-04-20 23:38:02 -06:00
|
|
|
#[derive(Archive, Serialize, Deserialize, Debug, Clone, PartialEq, Eq)]
|
2026-04-24 12:32:24 -06:00
|
|
|
pub struct FaultMessage {
|
|
|
|
|
/// Fixed protocol fault value.
|
|
|
|
|
pub fault: ProtocolFault,
|
2026-04-20 23:38:02 -06:00
|
|
|
}
|
|
|
|
|
|
2026-04-24 12:32:24 -06:00
|
|
|
/// Stable protocol fault set.
|
|
|
|
|
#[repr(u8)]
|
|
|
|
|
#[derive(Archive, Serialize, Deserialize, Debug, Clone, Copy, PartialEq, Eq)]
|
|
|
|
|
pub enum ProtocolFault {
|
|
|
|
|
/// The destination leaf does not exist.
|
|
|
|
|
UnknownLeaf = 0x01,
|
|
|
|
|
/// The destination does not support the requested procedure.
|
|
|
|
|
UnknownProcedure = 0x02,
|
|
|
|
|
/// The source path was invalid for the receiving connection.
|
|
|
|
|
InvalidSourcePath = 0x03,
|
|
|
|
|
/// The sender did not match the expected hook peer.
|
|
|
|
|
InvalidHookPeer = 0x04,
|
|
|
|
|
/// The endpoint encountered an internal processing failure.
|
|
|
|
|
InternalError = 0x05,
|
2026-04-20 23:38:02 -06:00
|
|
|
}
|