message.rs 739 B

12345678910111213141516171819202122232425262728
  1. use actix::Message;
  2. use bytes::Bytes;
  3. use flowy_collaboration::entities::ws::DocumentWSData;
  4. use lib_ws::{WSMessage, WSModule};
  5. use std::convert::TryInto;
  6. #[derive(Debug, Message, Clone)]
  7. #[rtype(result = "()")]
  8. pub struct WsMessageAdaptor(pub Bytes);
  9. impl std::ops::Deref for WsMessageAdaptor {
  10. type Target = Bytes;
  11. fn deref(&self) -> &Self::Target { &self.0 }
  12. }
  13. impl std::convert::From<DocumentWSData> for WsMessageAdaptor {
  14. fn from(data: DocumentWSData) -> Self {
  15. let bytes: Bytes = data.try_into().unwrap();
  16. let msg = WSMessage {
  17. module: WSModule::Doc,
  18. data: bytes.to_vec(),
  19. };
  20. let bytes: Bytes = msg.try_into().unwrap();
  21. WsMessageAdaptor(bytes)
  22. }
  23. }