mirror of
https://framagit.org/ppom/reaction
synced 2026-03-14 12:45:47 +01:00
deactivate PatternStatus special formatting
This commit is contained in:
parent
40fc6e3380
commit
8080bae293
2 changed files with 30 additions and 30 deletions
|
|
@ -3,7 +3,7 @@ use std::collections::BTreeMap;
|
|||
use super::Match;
|
||||
|
||||
use serde::{
|
||||
ser::{SerializeMap, SerializeStruct},
|
||||
// ser::{SerializeMap, SerializeStruct},
|
||||
Deserialize, Serialize,
|
||||
};
|
||||
|
||||
|
|
@ -37,36 +37,36 @@ pub enum DaemonResponse {
|
|||
|
||||
pub type ClientStatus = BTreeMap<String, BTreeMap<String, BTreeMap<String, PatternStatus>>>;
|
||||
|
||||
#[derive(Debug, Default, Deserialize)]
|
||||
#[derive(Debug, Default, Deserialize, Serialize)]
|
||||
pub struct PatternStatus {
|
||||
pub matches: usize,
|
||||
pub actions: BTreeMap<String, Vec<String>>,
|
||||
}
|
||||
|
||||
impl Serialize for PatternStatus {
|
||||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||
where
|
||||
S: serde::Serializer,
|
||||
{
|
||||
// We only skip serializing emptiness if we're on a human-readable format
|
||||
// This means we're printing for user, not exchanging it over a socket
|
||||
if serializer.is_human_readable() {
|
||||
let ser_matches = self.matches != 0;
|
||||
let ser_actions = !self.actions.is_empty();
|
||||
let mut state =
|
||||
serializer.serialize_map(Some(ser_matches as usize + ser_actions as usize))?;
|
||||
if ser_matches {
|
||||
state.serialize_entry("matches", &self.matches)?;
|
||||
}
|
||||
if ser_actions {
|
||||
state.serialize_entry("actions", &self.actions)?;
|
||||
}
|
||||
state.end()
|
||||
} else {
|
||||
let mut state = serializer.serialize_struct("PatternStatus", 2)?;
|
||||
state.serialize_field("matches", &self.matches)?;
|
||||
state.serialize_field("actions", &self.actions)?;
|
||||
state.end()
|
||||
}
|
||||
}
|
||||
}
|
||||
// impl Serialize for PatternStatus {
|
||||
// fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||
// where
|
||||
// S: serde::Serializer,
|
||||
// {
|
||||
// // We only skip serializing emptiness if we're on a human-readable format
|
||||
// // This means we're printing for user, not exchanging it over a socket
|
||||
// if serializer.is_human_readable() {
|
||||
// let ser_matches = self.matches != 0;
|
||||
// let ser_actions = !self.actions.is_empty();
|
||||
// let mut state =
|
||||
// serializer.serialize_map(Some(ser_matches as usize + ser_actions as usize))?;
|
||||
// if ser_matches {
|
||||
// state.serialize_entry("matches", &self.matches)?;
|
||||
// }
|
||||
// if ser_actions {
|
||||
// state.serialize_entry("actions", &self.actions)?;
|
||||
// }
|
||||
// state.end()
|
||||
// } else {
|
||||
// let mut state = serializer.serialize_struct("PatternStatus", 2)?;
|
||||
// state.serialize_field("matches", &self.matches)?;
|
||||
// state.serialize_field("actions", &self.actions)?;
|
||||
// state.end()
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
|
|
|||
|
|
@ -183,7 +183,7 @@ pub async fn socket_manager(
|
|||
};
|
||||
// Encode
|
||||
let encoded_response =
|
||||
or_next!("failed to serialize response", bin.serialize(&response));
|
||||
or_next!("failed to serialize response", bin.serialize::<DaemonResponse>(&response));
|
||||
or_next!(
|
||||
"failed to send response:",
|
||||
transport.send(Bytes::from(encoded_response)).await
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue