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 54a7973
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 16 deletions.
20 changes: 8 additions & 12 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 @@ -261,27 +260,24 @@ impl App {
.id_source("selected_message_attributes_collapsing_header")
.default_open(false)
.show(ui, |ui| {
if message.attributes.is_empty() {
if message
.attributes_json
.as_object()
.unwrap()
.is_empty()
{
ui.monospace("<Empty>");
} else {
JsonTree::new(
format!(
"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 54a7973

Please sign in to comment.