Skip to main content

rustmeter_beacon_core/
lib.rs

1#![cfg_attr(not(feature = "std"), no_std)]
2
3pub mod buffer;
4pub mod protocol;
5pub mod time_delta;
6pub mod tracing;
7pub mod varint;
8
9#[cfg(test)]
10pub mod mocks;
11
12#[inline(always)]
13pub fn compressed_task_id(task_id: u32) -> u16 {
14    // Step 1: Ignore alignment.
15    // We discard the lowest 2 bits (4-byte alignment).
16    let shifted = task_id >> 2;
17
18    // Step 2: XOR-Fold for safety.
19    // In case we have > 256KB memory or weird layout,
20    let folded = (shifted ^ (shifted >> 16)) as u16;
21
22    folded
23}
24
25unsafe extern "Rust" {
26    pub fn get_current_core_id() -> u8;
27}
28
29#[cfg(feature = "std")]
30mod std_core_id {
31    #[unsafe(no_mangle)]
32    unsafe fn get_current_core_id() -> u8 {
33        0
34    }
35}