Trait pea2pea::protocols::Writing [−][src]
pub trait Writing: Pea2Pea where
Self: Clone + Send + Sync + 'static, {
type Message: Send;
fn write_message<W: Write>(
&self,
target: SocketAddr,
message: &Self::Message,
writer: &mut W
) -> Result<()>;
fn enable_writing(&self) { ... }
fn write_to_stream<'life0, 'life1, 'life2, 'async_trait, W: AsyncWrite + Unpin + Send>(
&'life0 self,
message: Self::Message,
addr: SocketAddr,
buffer: &'life1 mut Vec<u8>,
writer: &'life2 mut W
) -> Pin<Box<dyn Future<Output = Result<usize>> + Send + 'async_trait>>
where
W: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
Self: Sync + 'async_trait,
{ ... }
fn send_direct_message(
&self,
addr: SocketAddr,
message: Self::Message
) -> Result<()> { ... }
fn send_broadcast(&self, message: Self::Message)
where
Self::Message: Clone,
{ ... }
}
Expand description
Can be used to specify and enable writing, i.e. sending outbound messages. If the Handshake
protocol is enabled too, it goes into force only after the handshake has been concluded.
Associated Types
Required methods
fn write_message<W: Write>(
&self,
target: SocketAddr,
message: &Self::Message,
writer: &mut W
) -> Result<()>
fn write_message<W: Write>(
&self,
target: SocketAddr,
message: &Self::Message,
writer: &mut W
) -> Result<()>
Writes the provided payload to the given intermediate writer; the payload can get prepended with a header indicating its length, be suffixed with a character indicating that it’s complete, etc.
Provided methods
fn enable_writing(&self)
fn enable_writing(&self)
Prepares the node to send messages.
fn write_to_stream<'life0, 'life1, 'life2, 'async_trait, W: AsyncWrite + Unpin + Send>(
&'life0 self,
message: Self::Message,
addr: SocketAddr,
buffer: &'life1 mut Vec<u8>,
writer: &'life2 mut W
) -> Pin<Box<dyn Future<Output = Result<usize>> + Send + 'async_trait>> where
W: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
Self: Sync + 'async_trait,
fn write_to_stream<'life0, 'life1, 'life2, 'async_trait, W: AsyncWrite + Unpin + Send>(
&'life0 self,
message: Self::Message,
addr: SocketAddr,
buffer: &'life1 mut Vec<u8>,
writer: &'life2 mut W
) -> Pin<Box<dyn Future<Output = Result<usize>> + Send + 'async_trait>> where
W: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
Self: Sync + 'async_trait,
Writes the given message to the given writer, using the provided intermediate buffer; returns the number of bytes written to the writer.
fn send_direct_message(
&self,
addr: SocketAddr,
message: Self::Message
) -> Result<()>
fn send_direct_message(
&self,
addr: SocketAddr,
message: Self::Message
) -> Result<()>
Sends the provided message to the specified SocketAddr
.
fn send_broadcast(&self, message: Self::Message) where
Self::Message: Clone,
fn send_broadcast(&self, message: Self::Message) where
Self::Message: Clone,
Broadcasts the provided message to all peers.