sparkles_core/protocol/
headers.rs

1use alloc::string::{String, ToString};
2use bincode::{Decode, Encode};
3use crate::local_storage::id_mapping::IdMapping;
4use crate::{Timestamp, TimestampProvider};
5use crate::consts::PROTOCOL_VERSION;
6
7/// This header describe byte buffer filled with encoded sparkles events.
8/// This header is thread-local. Each thread events packet has its own header and buffer.
9#[derive(Encode, Decode, Clone, Debug, Default)]
10pub struct LocalPacketHeader {
11    /// Globally unique order number of the spawned thread
12    pub thread_ord_id: u64,
13    pub thread_info: ThreadInfo,
14
15    /// Timestamp of the first event in a buffer
16    pub start_timestamp: u64,
17    /// Timestamp of the last event in a buffer
18    pub end_timestamp: u64,
19
20    pub id_store: IdMapping,
21}
22
23#[derive(Encode, Decode, Clone, Debug, Default)]
24pub struct ThreadInfo {
25    pub thread_id: u64,
26    pub new_thread_name: Option<String>,
27}
28
29#[derive(Encode, Decode, Clone, Debug)]
30pub struct SparklesMachineInfo {
31    pub ver: (u8, u8),
32    pub process_name: String,
33    pub pid: u32,
34    pub timestamp_max_value: u64
35}
36
37impl SparklesMachineInfo {
38    pub fn new(process_name: String, pid: u32) -> Self {
39        Self {
40            pid,
41            process_name,
42            ver: PROTOCOL_VERSION,
43            timestamp_max_value: Timestamp::MAX_VALUE,
44        }
45    }
46}
47
48impl Default for SparklesMachineInfo {
49    fn default() -> Self {
50        Self {
51            process_name: "unknown".to_string(),
52            pid: 0,
53            ver: PROTOCOL_VERSION,
54            timestamp_max_value: Timestamp::MAX_VALUE,
55        }
56    }
57}