Files
unshell/src/protocol/mod.rs
T

44 lines
1.3 KiB
Rust
Raw Normal View History

2026-04-24 12:32:24 -06:00
//! Canonical UnShell protocol modules.
//!
2026-04-24 12:32:24 -06:00
//! The wire model matches `PROTOCOL.md` directly.
2026-04-24 12:32:24 -06:00
pub mod codec;
pub mod introspection;
2026-04-24 13:37:30 -06:00
pub mod tree;
mod types;
2026-04-24 12:32:24 -06:00
pub mod validation;
2026-04-24 13:37:30 -06:00
#[cfg(test)]
mod tests;
2026-04-24 12:32:24 -06:00
pub use codec::{
2026-04-24 13:37:30 -06:00
FrameBytes, FrameCodec, FrameError, ParsedFrame, RkyvCodec, deserialize_archived_bytes,
2026-04-24 12:32:24 -06:00
};
pub use introspection::{EndpointIntrospection, LeafIntrospection, LeafIntrospectionSummary};
pub use types::{
CallMessage, DataMessage, FaultMessage, HookTarget, PacketHeader, PacketType, ProtocolFault,
};
pub use validation::{ValidationError, validate_call, validate_header, validate_procedure_id};
2026-04-24 13:37:30 -06:00
/// Encodes a header and payload with the crate's default frame codec.
///
/// This is a convenience wrapper around [`RkyvCodec`] for callers that do not
/// need to choose a codec explicitly.
2026-04-24 13:37:30 -06:00
pub fn encode_packet<P>(header: &PacketHeader, payload: &P) -> Result<FrameBytes, FrameError>
where
P: for<'a> rkyv::Serialize<
rkyv::api::high::HighSerializer<
rkyv::util::AlignedVec,
rkyv::ser::allocator::ArenaHandle<'a>,
rkyv::rancor::Error,
>,
>,
{
codec::encode_packet(header, payload)
}
/// Decodes a framed packet with the crate's default frame codec.
2026-04-24 13:37:30 -06:00
pub fn decode_frame(bytes: &[u8]) -> Result<ParsedFrame<'_>, FrameError> {
codec::decode_frame(bytes)
}