rustmeter-beacon-core 0.2.0

Core library for rustmeter-beacon
Documentation
#![cfg_attr(not(feature = "std"), no_std)]

pub mod buffer;
pub mod protocol;
pub mod time_delta;
pub mod tracing;
pub mod varint;

#[cfg(test)]
pub mod mocks;

#[inline(always)]
pub fn compressed_task_id(task_id: u32) -> u16 {
    // Step 1: Ignore alignment.
    // We discard the lowest 2 bits (4-byte alignment).
    let shifted = task_id >> 2;

    // Step 2: XOR-Fold for safety.
    // In case we have > 256KB memory or weird layout,
    let folded = (shifted ^ (shifted >> 16)) as u16;

    folded
}

unsafe extern "Rust" {
    pub fn get_current_core_id() -> u8;
}

#[cfg(feature = "std")]
mod std_core_id {
    #[unsafe(no_mangle)]
    unsafe fn get_current_core_id() -> u8 {
        0
    }
}