1use crate::{
2 config::ClockType,
3 types::{Event, EventCount, FieldValue, SequenceNumber, StreamId, Timestamp},
4};
5use internment::Intern;
6use serde::{Deserialize, Serialize};
7use uuid::Uuid;
89#[derive(Clone, PartialEq, Debug, Serialize, Deserialize)]
10pub struct Packet {
11pub header: PacketHeader,
12pub context: PacketContext,
13pub events: Vec<Event>,
14}
1516#[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash, Debug, Serialize, Deserialize)]
17pub struct PacketHeader {
18/// Magic number ([`PacketHeader::MAGIC`]) specifies that this is a CTF packet.
19pub magic_number: Option<u32>,
20/// Trace UUID, used to ensure the event packet match the metadata used.
21pub trace_uuid: Option<Uuid>,
22/// Stream ID, used as reference to stream description in metadata.
23pub stream_id: StreamId,
24/// Stream name
25pub stream_name: Intern<String>,
26/// Name of this stream's default clock
27pub clock_name: Option<Intern<String>>,
28/// This stream's clock type
29pub clock_type: Option<Intern<ClockType>>,
30}
3132impl PacketHeader {
33pub const MAGIC: u32 = 0xC1FC_1FC1;
34}
3536#[derive(Clone, PartialEq, Debug, Serialize, Deserialize)]
37pub struct PacketContext {
38/// Event packet size (in bits, includes padding).
39pub packet_size_bits: usize,
40/// Event packet content size (in bits).
41pub content_size_bits: usize,
42/// Time-stamp at the beginning of the event packet.
43pub beginning_timestamp: Option<Timestamp>,
44/// Time-stamp at the end of the event packet.
45pub end_timestamp: Option<Timestamp>,
46/// Snapshot of a per-stream free-running counter,
47 /// counting the number of events discarded that were supposed to be
48 /// written in the stream after the last event in the event packet.
49pub events_discarded: Option<EventCount>,
50/// Per-stream event packet sequence count.
51pub sequence_number: Option<SequenceNumber>,
52/// Extra, user-defined members to be appended to this data stream type’s packet context structure field type.
53pub extra_members: Vec<(Intern<String>, FieldValue)>,
54}
5556impl PacketContext {
57/// Event packet size (in bytes).
58pub fn packet_size(&self) -> usize {
59self.packet_size_bits >> 3
60}
6162/// Event packet content size (in bytes).
63pub fn content_size(&self) -> usize {
64self.content_size_bits >> 3
65}
66}