Skip to content

Commit 9461501

Browse files
committed
update: set attributes to optional
1 parent 566af62 commit 9461501

File tree

1 file changed

+3
-5
lines changed

1 file changed

+3
-5
lines changed

src/message.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ use std::collections::HashMap;
66
#[derive(Deserialize, Clone, Serialize)]
77
pub struct EncodedMessage {
88
data: String,
9-
attributes: HashMap<String, String>,
9+
#[serde(skip_serializing_if = "Option::is_none")]
10+
attributes: Option<HashMap<String, String>>,
1011
}
1112

1213
pub trait FromPubSubMessage
@@ -24,10 +25,7 @@ impl EncodedMessage {
2425
pub fn new<T: serde::Serialize>(data: &T, attributes: Option<HashMap<String, String>>) -> Self {
2526
let json = serde_json::to_string(data).unwrap();
2627
let data = base64::encode(&json);
27-
EncodedMessage {
28-
data,
29-
attributes: attributes.unwrap_or_default(),
30-
}
28+
EncodedMessage { data, attributes }
3129
}
3230
}
3331

0 commit comments

Comments
 (0)