2021-07-21 15:43:05 +08:00
|
|
|
use flowy_derive::ProtoBuf;
|
2021-09-08 18:25:32 +08:00
|
|
|
use std::{fmt, fmt::Formatter};
|
2021-07-21 15:43:05 +08:00
|
|
|
|
2023-01-26 15:40:23 +08:00
|
|
|
#[derive(Debug, Clone, ProtoBuf, serde::Serialize)]
|
2021-10-14 14:34:22 +08:00
|
|
|
pub struct SubscribeObject {
|
2021-07-21 15:43:05 +08:00
|
|
|
#[pb(index = 1)]
|
2021-09-08 13:50:20 +08:00
|
|
|
pub source: String,
|
2021-07-21 15:43:05 +08:00
|
|
|
|
|
|
|
#[pb(index = 2)]
|
|
|
|
pub ty: i32,
|
|
|
|
|
|
|
|
#[pb(index = 3)]
|
2021-09-07 17:12:03 +08:00
|
|
|
pub id: String,
|
2021-07-21 15:43:05 +08:00
|
|
|
|
|
|
|
#[pb(index = 4, one_of)]
|
2021-09-07 17:12:03 +08:00
|
|
|
pub payload: Option<Vec<u8>>,
|
|
|
|
|
|
|
|
#[pb(index = 5, one_of)]
|
|
|
|
pub error: Option<Vec<u8>>,
|
2021-07-21 15:43:05 +08:00
|
|
|
}
|
|
|
|
|
2021-10-14 14:34:22 +08:00
|
|
|
impl std::fmt::Display for SubscribeObject {
|
2021-09-08 18:25:32 +08:00
|
|
|
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
|
2023-01-05 21:27:21 +08:00
|
|
|
f.write_str(&format!("{} changed: ", &self.source))?;
|
2021-09-08 18:25:32 +08:00
|
|
|
if let Some(payload) = &self.payload {
|
2023-01-05 21:27:21 +08:00
|
|
|
f.write_str(&format!("send {} payload", payload.len()))?;
|
2021-09-08 18:25:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if let Some(payload) = &self.error {
|
2023-01-05 21:27:21 +08:00
|
|
|
f.write_str(&format!("receive {} error", payload.len()))?;
|
2021-09-08 18:25:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-10-14 14:34:22 +08:00
|
|
|
impl std::default::Default for SubscribeObject {
|
2021-07-21 15:43:05 +08:00
|
|
|
fn default() -> Self {
|
|
|
|
Self {
|
2021-09-08 13:50:20 +08:00
|
|
|
source: "".to_string(),
|
2021-07-25 08:13:59 +08:00
|
|
|
ty: 0,
|
2021-09-07 17:12:03 +08:00
|
|
|
id: "".to_string(),
|
|
|
|
payload: None,
|
|
|
|
error: None,
|
2021-07-21 15:43:05 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|