forked from aws/aws-lambda-rust-runtime
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmod.rs
More file actions
89 lines (83 loc) · 3.31 KB
/
Copy pathmod.rs
File metadata and controls
89 lines (83 loc) · 3.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
use serde::{Deserialize, Serialize};
#[cfg(feature = "catch-all-fields")]
use serde_json::Value;
use std::collections::HashMap;
use crate::custom_serde::deserialize_lambda_map;
#[derive(Debug, Default, Clone, Eq, PartialEq, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct ActiveMqEvent {
#[serde(default)]
pub event_source: Option<String>,
#[serde(default)]
pub event_source_arn: Option<String>,
pub messages: Vec<ActiveMqMessage>,
/// Catchall to catch any additional fields that were present but not explicitly defined by this struct.
/// Enabled with Cargo feature `catch-all-fields`.
/// If `catch-all-fields` is disabled, any additional fields that are present will be ignored.
#[cfg(feature = "catch-all-fields")]
#[cfg_attr(docsrs, doc(cfg(feature = "catch-all-fields")))]
#[serde(flatten)]
pub other: serde_json::Map<String, Value>,
}
#[derive(Debug, Default, Clone, Eq, PartialEq, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct ActiveMqMessage {
#[serde(default)]
#[serde(rename = "messageID")]
pub message_id: Option<String>,
#[serde(default)]
pub message_type: Option<String>,
pub timestamp: i64,
pub delivery_mode: i64,
#[serde(default)]
#[serde(rename = "correlationID")]
pub correlation_id: Option<String>,
#[serde(default)]
pub reply_to: Option<String>,
pub destination: ActiveMqDestination,
pub redelivered: bool,
#[serde(default)]
pub type_: Option<String>,
pub expiration: i64,
pub priority: i64,
#[serde(default)]
pub data: Option<String>,
pub broker_in_time: i64,
pub broker_out_time: i64,
#[serde(deserialize_with = "deserialize_lambda_map")]
#[serde(default)]
pub properties: HashMap<String, String>,
/// Catchall to catch any additional fields that were present but not explicitly defined by this struct.
/// Enabled with Cargo feature `catch-all-fields`.
/// If `catch-all-fields` is disabled, any additional fields that are present will be ignored.
#[cfg(feature = "catch-all-fields")]
#[cfg_attr(docsrs, doc(cfg(feature = "catch-all-fields")))]
#[serde(flatten)]
pub other: serde_json::Map<String, Value>,
}
#[derive(Debug, Default, Clone, Eq, PartialEq, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct ActiveMqDestination {
#[serde(default)]
pub physical_name: Option<String>,
/// Catchall to catch any additional fields that were present but not explicitly defined by this struct.
/// Enabled with Cargo feature `catch-all-fields`.
/// If `catch-all-fields` is disabled, any additional fields that are present will be ignored.
#[cfg(feature = "catch-all-fields")]
#[cfg_attr(docsrs, doc(cfg(feature = "catch-all-fields")))]
#[serde(flatten)]
pub other: serde_json::Map<String, Value>,
}
#[cfg(test)]
mod test {
use super::*;
#[test]
#[cfg(feature = "activemq")]
fn example_activemq_event() {
let data = include_bytes!("../../fixtures/example-activemq-event.json");
let parsed: ActiveMqEvent = serde_json::from_slice(data).unwrap();
let output: String = serde_json::to_string(&parsed).unwrap();
let reparsed: ActiveMqEvent = serde_json::from_slice(output.as_bytes()).unwrap();
assert_eq!(parsed, reparsed);
}
}