From 54a79739631102fb5a99fd85a3ee717080714525 Mon Sep 17 00:00:00 2001 From: dmackdev Date: Sat, 14 Oct 2023 20:05:39 +0100 Subject: [PATCH] Replaced attribues with json value. --- pubsubman/src/app.rs | 20 ++++++++----------- pubsubman_backend/src/model/pubsub_message.rs | 16 +++++++++++---- 2 files changed, 20 insertions(+), 16 deletions(-) diff --git a/pubsubman/src/app.rs b/pubsubman/src/app.rs index 72e0f90..82d7c43 100644 --- a/pubsubman/src/app.rs +++ b/pubsubman/src/app.rs @@ -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::{ @@ -261,7 +260,12 @@ 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(""); } else { JsonTree::new( @@ -269,19 +273,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); } diff --git a/pubsubman_backend/src/model/pubsub_message.rs b/pubsubman_backend/src/model/pubsub_message.rs index f53c6a7..08b4632 100644 --- a/pubsubman_backend/src/model/pubsub_message.rs +++ b/pubsubman_backend/src/model/pubsub_message.rs @@ -1,7 +1,7 @@ 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 { @@ -9,7 +9,7 @@ pub struct PubsubMessage { pub publish_time: Option>, pub data: String, pub data_json: Value, - pub attributes: HashMap, + pub attributes_json: Value, } impl From for PubsubMessage { @@ -30,12 +30,20 @@ impl From 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, } } }