use serde::{Deserialize, Serialize};
#[repr(C, align(64))]
#[derive(Clone, Copy, Debug, Serialize, Deserialize)]
pub struct PulseFrameHeader {
pub magic: u32,
pub version: u16,
pub flags: u16,
pub rpki_fingerprint: [u8; 32],
pub zcmk_bid: u64,
pub semantic_hash: u64,
pub priority: u8,
pub ttl: u8,
pub timestamp_ns: u32,
pub checksum: u16,
}
impl PulseFrameHeader {
#[inline(always)]
pub fn as_bytes(&self) -> &[u8] {
unsafe { std::slice::from_raw_parts(self as *const _ as *const u8, 64) }
}
#[inline(always)]
pub fn new(fingerprint: [u8; 32], bid: u64, sem_hash: u64) -> Self {
let now = std::time::Instant::now().elapsed().as_nanos() as u32;
Self {
magic: 0x5254_5450,
version: 0x0100,
flags: 0b0000_0110, rpki_fingerprint: fingerprint,
zcmk_bid: bid,
semantic_hash: sem_hash,
priority: 128, ttl: 64, timestamp_ns: now,
checksum: 0,
}
}
}
pub fn on_pulse_received(frame: &[u8]) {
if frame.len() < 64 {
handle_malformed_pulse();
return;
}
let header = unsafe { &*(frame.as_ptr() as *const PulseFrameHeader) };
if header.magic != 0x5254_5450 {
return; }
#[cfg(debug_assertions)]
println!(
"\x1b[1;36m[RTTP-PULSE]\x1b[0m 64-byte Header verified. Ready for Reflex Arc."
);
}
#[cold]
#[inline(never)]
fn handle_malformed_pulse() {
eprintln!("\x1b[1;31m[RTTP-ERROR]\x1b[0m Inbound frame size underflow. Pathogen discarded.");
}