1use crate::ds::DeliveryServiceError;
3#[derive(Debug, Clone, PartialEq, Eq)]
5pub struct OutboundPacket {
6 pub payload: Vec<u8>,
7 pub subtopic: String,
8 pub group_id: String,
9 pub app_id: Vec<u8>,
12}
13
14impl OutboundPacket {
15 pub fn new(payload: Vec<u8>, subtopic: &str, group_id: &str, app_id: &[u8]) -> Self {
16 Self {
17 payload,
18 subtopic: subtopic.to_string(),
19 group_id: group_id.to_string(),
20 app_id: app_id.to_vec(),
21 }
22 }
23}
24
25#[derive(Debug, Clone, PartialEq, Eq)]
27pub struct InboundPacket {
28 pub payload: Vec<u8>,
29 pub subtopic: String,
30 pub group_id: String,
31 pub app_id: Vec<u8>,
33 pub timestamp: i64,
34}
35
36impl InboundPacket {
37 pub fn new(
38 payload: Vec<u8>,
39 subtopic: &str,
40 group_id: &str,
41 app_id: Vec<u8>,
42 timestamp: i64,
43 ) -> Self {
44 Self {
45 payload,
46 subtopic: subtopic.to_string(),
47 group_id: group_id.to_string(),
48 app_id,
49 timestamp,
50 }
51 }
52}
53
54pub trait DeliveryService: Send + Sync + 'static {
55 fn send(&self, pkt: OutboundPacket) -> Result<String, DeliveryServiceError>;
57
58 fn subscribe(&self) -> std::sync::mpsc::Receiver<InboundPacket>;
65}