Reformat lines.

This commit is contained in:
Michael Mikovsky
2026-04-25 12:41:10 -06:00
parent 080f55ddd3
commit 4a131e6b63
9 changed files with 77 additions and 37 deletions
+10 -13
View File
@@ -1,9 +1,6 @@
//! Framed packet encoding and decoding.
use core::{fmt, mem};
use rkyv::{
Serialize, access, deserialize, rancor::Error, to_bytes,
util::AlignedVec,
};
use rkyv::{Serialize, access, deserialize, rancor::Error, to_bytes, util::AlignedVec};
use super::types::{
ArchivedCallMessage, ArchivedDataMessage, ArchivedFaultMessage, ArchivedPacketHeader,
@@ -84,18 +81,13 @@ impl<'a> ParsedFrame<'a> {
pub fn encode_packet<P>(header: &PacketHeader, payload: &P) -> Result<FrameBytes, FrameError>
where
P: for<'a> Serialize<
rkyv::api::high::HighSerializer<
AlignedVec,
rkyv::ser::allocator::ArenaHandle<'a>,
Error,
>,
rkyv::api::high::HighSerializer<AlignedVec, rkyv::ser::allocator::ArenaHandle<'a>, Error>,
>,
{
let header_bytes: FrameBytes = to_bytes::<Error>(header).map_err(FrameError::Serialize)?;
let payload_bytes: FrameBytes = to_bytes::<Error>(payload).map_err(FrameError::Serialize)?;
let header_len = u32::try_from(header_bytes.len()).map_err(|_| FrameError::LengthOverflow)?;
let payload_len =
u32::try_from(payload_bytes.len()).map_err(|_| FrameError::LengthOverflow)?;
let payload_len = u32::try_from(payload_bytes.len()).map_err(|_| FrameError::LengthOverflow)?;
let header_start = 8usize;
let payload_start = align_up(header_start + header_bytes.len(), SECTION_ALIGN);
@@ -105,7 +97,10 @@ where
frame.extend_from_slice(&header_len.to_be_bytes());
frame.extend_from_slice(&payload_len.to_be_bytes());
frame.extend_from_slice(&header_bytes);
append_padding(&mut frame, payload_start - (header_start + header_bytes.len()));
append_padding(
&mut frame,
payload_start - (header_start + header_bytes.len()),
);
frame.extend_from_slice(&payload_bytes);
Ok(frame)
}
@@ -131,7 +126,9 @@ pub fn decode_frame(bytes: &[u8]) -> Result<ParsedFrame<'_>, FrameError> {
}
let header = deserialize_section::<ArchivedPacketHeader, PacketHeader>(
bytes.get(header_start..header_end).ok_or(FrameError::Truncated)?,
bytes
.get(header_start..header_end)
.ok_or(FrameError::Truncated)?,
FrameError::InvalidHeader,
)?;
+1 -2
View File
@@ -14,8 +14,7 @@ pub use codec::{
encode_packet,
};
pub use introspection::{
EndpointIntrospection, INTROSPECTION_PROCEDURE_ID, LeafIntrospection,
LeafIntrospectionSummary,
EndpointIntrospection, INTROSPECTION_PROCEDURE_ID, LeafIntrospection, LeafIntrospectionSummary,
};
pub use types::{
CallMessage, DataMessage, FaultMessage, HookTarget, PacketHeader, PacketType, ProtocolFault,
+9 -3
View File
@@ -2,7 +2,7 @@ use alloc::{borrow::ToOwned, string::String, vec, vec::Vec};
use crate::protocol::{
CallMessage, FaultMessage, FrameError, HookTarget, PacketHeader, PacketType, ProtocolFault,
ValidationError, SECTION_ALIGN, decode_frame, encode_packet, validate_call, validate_header,
SECTION_ALIGN, ValidationError, decode_frame, encode_packet, validate_call, validate_header,
validate_procedure_id,
};
@@ -34,7 +34,10 @@ fn packet_framing_roundtrip_preserves_header_and_payload() {
assert_eq!(parsed.header(), &header);
assert_eq!(parsed.packet_type(), PacketType::Call);
assert_eq!(parsed.deserialize_call().expect("call should deserialize"), call);
assert_eq!(
parsed.deserialize_call().expect("call should deserialize"),
call
);
}
#[test]
@@ -99,5 +102,8 @@ fn truncated_frames_are_rejected() {
let frame = encode_packet(&header, &message).expect("frame should encode");
let truncated = &frame[..frame.len() - 1];
assert!(matches!(decode_frame(truncated), Err(FrameError::Truncated)));
assert!(matches!(
decode_frame(truncated),
Err(FrameError::Truncated)
));
}
+4 -1
View File
@@ -243,7 +243,10 @@ fn pending_hook_fault_is_delivered_before_activation() {
.expect("pending hook should insert");
let outcome = endpoint
.handle_introspection(&header, Some(crate::protocol::tree::HookKey::new(path(&["client"]), 11)))
.handle_introspection(
&header,
Some(crate::protocol::tree::HookKey::new(path(&["client"]), 11)),
)
.expect("introspection should handle pending hook");
assert!(outcome.forward.is_some() || outcome.event.is_some());
+12 -4
View File
@@ -167,7 +167,10 @@ impl ProtocolEndpoint {
match self.decide_route(&header.dst_path) {
RouteDecision::Local => self.handle_local_call(header, call),
route => Ok(EndpointOutcome::forward(route, encode_packet(&header, &call)?)),
route => Ok(EndpointOutcome::forward(
route,
encode_packet(&header, &call)?,
)),
}
}
@@ -179,7 +182,8 @@ impl ProtocolEndpoint {
data: Vec<u8>,
end_hook: bool,
) -> Result<FrameBytes, EndpointError> {
let (header, message) = self.prepare_data(dst_path, hook_id, procedure_id, data, end_hook)?;
let (header, message) =
self.prepare_data(dst_path, hook_id, procedure_id, data, end_hook)?;
Ok(encode_packet(&header, &message)?)
}
@@ -191,7 +195,8 @@ impl ProtocolEndpoint {
data: Vec<u8>,
end_hook: bool,
) -> Result<EndpointOutcome, EndpointError> {
let (header, message) = self.prepare_data(dst_path, hook_id, procedure_id, data, end_hook)?;
let (header, message) =
self.prepare_data(dst_path, hook_id, procedure_id, data, end_hook)?;
if end_hook {
let sender_key = self
@@ -205,7 +210,10 @@ impl ProtocolEndpoint {
match self.decide_route(&header.dst_path) {
RouteDecision::Local => self.handle_local_data(header, message),
route => Ok(EndpointOutcome::forward(route, encode_packet(&header, &message)?)),
route => Ok(EndpointOutcome::forward(
route,
encode_packet(&header, &message)?,
)),
}
}
}
+20 -5
View File
@@ -32,8 +32,14 @@ impl ProtocolEndpoint {
let message = FaultMessage { fault };
match self.decide_route(&key.return_path) {
RouteDecision::Local => Ok(EndpointOutcome::event(LocalEvent::Fault { header, message })),
route => Ok(EndpointOutcome::forward(route, encode_packet(&header, &message)?)),
RouteDecision::Local => Ok(EndpointOutcome::event(LocalEvent::Fault {
header,
message,
})),
route => Ok(EndpointOutcome::forward(
route,
encode_packet(&header, &message)?,
)),
}
}
@@ -87,9 +93,15 @@ impl ProtocolEndpoint {
message: FaultMessage,
) -> Result<EndpointOutcome, EndpointError> {
let hook_id = header.hook_id.expect("validated");
if let Some(key) = self.hooks.resolve_active_key(&self.path, hook_id, &header.src_path) {
if let Some(key) = self
.hooks
.resolve_active_key(&self.path, hook_id, &header.src_path)
{
self.hooks.remove_active(&key);
return Ok(EndpointOutcome::event(LocalEvent::Fault { header, message }));
return Ok(EndpointOutcome::event(LocalEvent::Fault {
header,
message,
}));
}
let pending_key = HookKey::new(self.path.clone(), hook_id);
@@ -99,7 +111,10 @@ impl ProtocolEndpoint {
.is_some_and(|pending| pending.caller_src_path == header.src_path)
{
self.hooks.remove_pending(&pending_key);
return Ok(EndpointOutcome::event(LocalEvent::Fault { header, message }));
return Ok(EndpointOutcome::event(LocalEvent::Fault {
header,
message,
}));
}
Ok(EndpointOutcome::dropped())
+7 -4
View File
@@ -70,13 +70,16 @@ impl ProtocolEndpoint {
}
match self.decide_route(&key.return_path) {
super::super::RouteDecision::Local => Ok(EndpointOutcome::event(
super::core::LocalEvent::Data {
super::super::RouteDecision::Local => {
Ok(EndpointOutcome::event(super::core::LocalEvent::Data {
header: response_header,
message: response,
},
}))
}
route => Ok(EndpointOutcome::forward(
route,
encode_packet(&response_header, &response)?,
)),
route => Ok(EndpointOutcome::forward(route, encode_packet(&response_header, &response)?)),
}
}
}
+11 -4
View File
@@ -49,7 +49,11 @@ impl ProtocolEndpoint {
Some(leaf_name) => self
.leaves
.get(leaf_name)
.map(|leaf| leaf.procedures.iter().any(|procedure| procedure == &message.procedure_id))
.map(|leaf| {
leaf.procedures
.iter()
.any(|procedure| procedure == &message.procedure_id)
})
.unwrap_or(false),
None => self.endpoint_procedures.contains(&message.procedure_id),
};
@@ -105,12 +109,15 @@ impl Endpoint for ProtocolEndpoint {
RouteDecision::Child(index) => {
Ok(EndpointOutcome::forward(RouteDecision::Child(index), frame))
}
RouteDecision::Parent => Ok(EndpointOutcome::forward(RouteDecision::Parent, frame)),
RouteDecision::Parent => {
Ok(EndpointOutcome::forward(RouteDecision::Parent, frame))
}
RouteDecision::Drop => Ok(EndpointOutcome::dropped()),
RouteDecision::Local => {
let (header, payload) = parsed.into_parts();
let message =
deserialize_archived_bytes::<ArchivedCallMessage, CallMessage>(payload)?;
let message = deserialize_archived_bytes::<ArchivedCallMessage, CallMessage>(
payload,
)?;
validate_call(&header, &message)?;
self.handle_local_call(header, message)
}
+3 -1
View File
@@ -5,7 +5,9 @@ use alloc::{collections::BTreeMap, string::String, vec, vec::Vec};
/// Explicit test tree declaration used for configuration.
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum TreeNode {
Root { children: Vec<Self> },
Root {
children: Vec<Self>,
},
Endpoint {
segment: String,
leaves: Vec<LeafNode>,