Skip to content

Commit

Permalink
If the group doesn't exist, it doesn't output: null
Browse files Browse the repository at this point in the history
  • Loading branch information
rmqtt committed Sep 11, 2023
1 parent cb870f5 commit 631858b
Showing 1 changed file with 21 additions and 8 deletions.
29 changes: 21 additions & 8 deletions rmqtt/src/broker/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use std::rc::Rc;
use std::sync::Arc;
use std::time::{Duration, Instant};

use base64::{Engine as _, engine::general_purpose};
use base64::{engine::general_purpose, Engine as _};
use bitflags::bitflags;
use bytestring::ByteString;
use itertools::Itertools;
Expand All @@ -22,6 +22,7 @@ pub use ntex_mqtt::v3::{
codec::SubscribeReturnCode as SubscribeReturnCodeV3, HandshakeAck as HandshakeAckV3,
MqttSink as MqttSinkV3,
};
use tokio::sync::oneshot;

use ntex_mqtt::v5::codec::{PublishAckReason, RetainHandling};
pub use ntex_mqtt::v5::{
Expand All @@ -36,7 +37,6 @@ pub use ntex_mqtt::v5::{
};
use serde::de::{self, Deserialize, Deserializer};
use serde::ser::{Serialize, SerializeStruct, Serializer};
use tokio::sync::oneshot;

use crate::{MqttError, Result, Runtime};

Expand Down Expand Up @@ -565,10 +565,15 @@ pub struct SubOptionsV3 {
impl SubOptionsV3 {
#[inline]
pub fn to_json(&self) -> serde_json::Value {
json!({
let mut obj = json!({
"qos": self.qos.value(),
"group": self.shared_group,
})
});
if let Some(g) = &self.shared_group {
if let Some(obj) = obj.as_object_mut() {
obj.insert("group".into(), serde_json::Value::String(g.clone()));
}
}
obj
}
}

Expand Down Expand Up @@ -603,13 +608,21 @@ impl SubOptionsV5 {

#[inline]
pub fn to_json(&self) -> serde_json::Value {
json!({
let mut obj = json!({
"qos": self.qos.value(),
"group": self.shared_group,
"no_local": self.no_local,
"retain_as_published": self.retain_as_published,
"retain_handling": self.retain_handling_value(),
})
});
if let Some(obj) = obj.as_object_mut() {
if let Some(g) = &self.shared_group {
obj.insert("group".into(), serde_json::Value::String(g.clone()));
}
if let Some(id) = &self.id {
obj.insert("id".into(), serde_json::Value::Number(serde_json::Number::from(id.get())));
}
}
obj
}

#[inline]
Expand Down

0 comments on commit 631858b

Please sign in to comment.