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)]
|
|
|
|
pub struct ObservableSubject {
|
|
|
|
#[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-09-08 18:25:32 +08:00
|
|
|
impl std::fmt::Display for ObservableSubject {
|
|
|
|
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
|
|
|
|
let _ = f.write_str(&self.source)?;
|
|
|
|
let _ = f.write_str(&format!("-{}", self.ty))?;
|
|
|
|
if let Some(payload) = &self.payload {
|
|
|
|
let _ = f.write_str(&format!("-{} payload", payload.len()))?;
|
|
|
|
}
|
|
|
|
|
|
|
|
if let Some(payload) = &self.error {
|
|
|
|
let _ = f.write_str(&format!("-{} error", payload.len()))?;
|
|
|
|
}
|
|
|
|
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-07-21 15:43:05 +08:00
|
|
|
impl std::default::Default for ObservableSubject {
|
|
|
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|