Skip to content

Commit

Permalink
Replaced attribues with json value.
Browse files Browse the repository at this point in the history
  • Loading branch information
dmackdev committed Oct 14, 2023
1 parent 8924755 commit 4680d3a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 15 deletions.
13 changes: 2 additions & 11 deletions pubsubman/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ use pubsubman_backend::{
model::{PubsubMessage, SubscriptionName, TopicName},
Backend,
};
use serde_json::{Map, Value};
use tokio::sync::mpsc::{Receiver, Sender};

use crate::{
Expand Down Expand Up @@ -269,19 +268,11 @@ impl App {
"selected_message_attributes_json_{}",
&message.id
),
&Value::Object(Map::from_iter(
message.attributes.iter().map(|(k, v)| {
(k.to_owned(), Value::String(v.clone()))
}),
)),
&message.attributes_json,
)
.default_expand(egui_json_tree::DefaultExpand::All)
.response_callback(show_json_context_menu(
&Value::Object(Map::from_iter(
message.attributes.iter().map(|(k, v)| {
(k.to_owned(), Value::String(v.clone()))
}),
)),
&message.attributes_json,
))
.show(ui);
}
Expand Down
16 changes: 12 additions & 4 deletions pubsubman_backend/src/model/pubsub_message.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
use chrono::{DateTime, TimeZone, Utc};
use google_cloud_pubsub::subscriber::ReceivedMessage;
use serde_json::Value;
use std::{collections::HashMap, str};
use serde_json::{Map, Value};
use std::str;

#[derive(Debug, Clone, serde::Deserialize, serde::Serialize)]
pub struct PubsubMessage {
pub id: String,
pub publish_time: Option<DateTime<Utc>>,
pub data: String,
pub data_json: Value,
pub attributes: HashMap<String, String>,
pub attributes_json: Value,
}

impl From<ReceivedMessage> for PubsubMessage {
Expand All @@ -30,12 +30,20 @@ impl From<ReceivedMessage> for PubsubMessage {
Err(_) => Value::String(data.clone()),
};

let attributes_json = Value::Object(Map::from_iter(
value
.message
.attributes
.into_iter()
.map(|(k, v)| (k, Value::String(v))),
));

Self {
id: value.message.message_id,
publish_time,
data,
data_json,
attributes: value.message.attributes,
attributes_json,
}
}
}

0 comments on commit 4680d3a

Please sign in to comment.