pub struct DataChannel { /* private fields */ }Expand description
A channel that sends and receives typed protocol messages.
Wraps a raw Channel and provides automatic serialization via
ProtocolMessage::encode and ProtocolMessage::decode. Tracks
message counts for monitoring.
Implementations§
Source§impl DataChannel
impl DataChannel
Sourcepub fn new(channel: Arc<dyn Channel>, node_name: String) -> Self
pub fn new(channel: Arc<dyn Channel>, node_name: String) -> Self
Create a new DataChannel wrapping the given raw channel.
§Arguments
channel- The underlying channel for byte transport.node_name- The name of the peer node on this channel.
Sourcepub fn send_message(&self, msg: &ProtocolMessage) -> Result<()>
pub fn send_message(&self, msg: &ProtocolMessage) -> Result<()>
Send a protocol message through the channel.
The message is encoded to bytes via ProtocolMessage::encode and
sent through the underlying channel.
Sourcepub fn receive_message(
&self,
timeout: Duration,
) -> Result<Option<ProtocolMessage>>
pub fn receive_message( &self, timeout: Duration, ) -> Result<Option<ProtocolMessage>>
Receive a protocol message with a timeout.
Blocks until a message is available or the timeout expires.
Returns Ok(None) on timeout.
Sourcepub fn get_node_name(&self) -> &str
pub fn get_node_name(&self) -> &str
Get the peer node name.
Sourcepub fn messages_sent(&self) -> u64
pub fn messages_sent(&self) -> u64
Get the total number of messages sent.
Sourcepub fn messages_received(&self) -> u64
pub fn messages_received(&self) -> u64
Get the total number of messages received.
Auto Trait Implementations§
impl !Freeze for DataChannel
impl !RefUnwindSafe for DataChannel
impl !UnwindSafe for DataChannel
impl Send for DataChannel
impl Sync for DataChannel
impl Unpin for DataChannel
impl UnsafeUnpin for DataChannel
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more