subject.rs 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. use flowy_derive::ProtoBuf;
  2. use std::{fmt, fmt::Formatter};
  3. #[derive(Debug, Clone, ProtoBuf)]
  4. pub struct SubscribeObject {
  5. #[pb(index = 1)]
  6. pub source: String,
  7. #[pb(index = 2)]
  8. pub ty: i32,
  9. #[pb(index = 3)]
  10. pub id: String,
  11. #[pb(index = 4, one_of)]
  12. pub payload: Option<Vec<u8>>,
  13. #[pb(index = 5, one_of)]
  14. pub error: Option<Vec<u8>>,
  15. }
  16. impl std::fmt::Display for SubscribeObject {
  17. fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
  18. let _ = f.write_str(&format!("{} changed: ", &self.source))?;
  19. if let Some(payload) = &self.payload {
  20. let _ = f.write_str(&format!("send {} payload", payload.len()))?;
  21. }
  22. if let Some(payload) = &self.error {
  23. let _ = f.write_str(&format!("receive {} error", payload.len()))?;
  24. }
  25. Ok(())
  26. }
  27. }
  28. impl std::default::Default for SubscribeObject {
  29. fn default() -> Self {
  30. Self {
  31. source: "".to_string(),
  32. ty: 0,
  33. id: "".to_string(),
  34. payload: None,
  35. error: None,
  36. }
  37. }
  38. }