dcl_rpc/transports/
mod.rs

1//! Transports out of the box for the communications between two ends using Decentraland RPC.
2//!
3//! The Decentraland RPC implementation uses protobuf for the messages format and uses whatever transport or wire that meet the requirements of the [`Transport`] trait.
4//!
5use async_trait::async_trait;
6
7pub mod error;
8#[cfg(feature = "memory")]
9pub mod memory;
10#[cfg(feature = "websockets")]
11pub mod web_sockets;
12
13pub type TransportMessage = Vec<u8>;
14
15#[derive(Debug)]
16pub enum TransportError {
17    /// Error while the underlying transport is running.
18    ///
19    /// For example: A peer reset the connection in a websocket connection
20    ///
21    Internal(Box<dyn std::error::Error + Send + Sync>),
22    /// Transport is already closed
23    Closed,
24    /// When the received message is not a binary
25    NotBinaryMessage,
26}
27
28#[async_trait]
29pub trait Transport: Send + Sync {
30    async fn receive(&self) -> Result<TransportMessage, TransportError>;
31    async fn send(&self, message: TransportMessage) -> Result<(), TransportError>;
32    async fn close(&self);
33}