Skip to main content

winterbaume_iotdataplane/
types.rs

1use chrono::{DateTime, Utc};
2
3/// Represents a thing shadow document stored in the IoT Data Plane.
4#[derive(Debug, Clone)]
5pub struct ThingShadow {
6    pub thing_name: String,
7    pub shadow_name: Option<String>,
8    pub payload: Vec<u8>,
9    pub version: i64,
10    pub last_modified: DateTime<Utc>,
11}
12
13/// Key for identifying a shadow: (thing_name, shadow_name).
14/// Named shadows use Some(name), classic shadow uses None.
15#[derive(Debug, Clone, Hash, Eq, PartialEq)]
16pub struct ShadowKey {
17    pub thing_name: String,
18    pub shadow_name: Option<String>,
19}
20
21impl ShadowKey {
22    pub fn classic(thing_name: &str) -> Self {
23        Self {
24            thing_name: thing_name.to_string(),
25            shadow_name: None,
26        }
27    }
28
29    pub fn named(thing_name: &str, shadow_name: &str) -> Self {
30        Self {
31            thing_name: thing_name.to_string(),
32            shadow_name: Some(shadow_name.to_string()),
33        }
34    }
35}
36
37/// Represents an MQTT message published via the Publish API.
38#[derive(Debug, Clone)]
39pub struct PublishedMessage {
40    pub topic: String,
41    pub payload: Vec<u8>,
42    pub qos: i32,
43    pub retain: bool,
44    pub published_at: DateTime<Utc>,
45}
46
47/// Represents a retained MQTT message stored by topic.
48#[derive(Debug, Clone)]
49pub struct RetainedMessage {
50    pub topic: String,
51    pub payload: Vec<u8>,
52    pub qos: i32,
53    pub last_modified: DateTime<Utc>,
54}