1use crate::event::Event;
2
3#[cfg(feature = "serde")]
4use serde::{Deserialize, Serialize};
5
6#[derive(Debug, Clone)]
8#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
9pub struct AgentId {
10 pub id: u64,
12
13 pub instance_id: u16,
15
16 pub master_instance_id: u16,
18}
19
20impl AgentId {
21 #[inline]
23 pub const fn new(id: u64, instance_id: u16, master_instance_id: u16) -> Self {
24 Self {
25 id,
26 instance_id,
27 master_instance_id,
28 }
29 }
30
31 #[inline]
33 pub const fn without_master(id: u64, instance_id: u16) -> Self {
34 Self::new(id, instance_id, 0)
35 }
36
37 #[inline]
39 pub const fn from_src(event: &Event) -> Self {
40 Self::new(
41 event.src_agent,
42 event.src_instance_id,
43 event.src_master_instance_id,
44 )
45 }
46
47 #[inline]
49 pub const fn from_dst(event: &Event) -> Self {
50 Self::new(
51 event.dst_agent,
52 event.dst_instance_id,
53 event.dst_master_instance_id,
54 )
55 }
56
57 #[inline]
59 pub const fn has_master(&self) -> bool {
60 self.master_instance_id != 0
61 }
62}