48 lines
1.1 KiB
Rust
Raw Normal View History

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
#[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)]
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 {
f.write_str(&format!("{} changed: ", &self.source))?;
2021-09-08 18:25:32 +08:00
if let Some(payload) = &self.payload {
f.write_str(&format!("send {} payload", payload.len()))?;
2021-09-08 18:25:32 +08:00
}
if let Some(payload) = &self.error {
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 {
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
}
}
}