pub struct ByteStreams<OB, IB> {
pub outgoing: OB,
pub incoming: IB,
}Expand description
A component that communicates over byte streams (stdin/stdout, sockets, pipes, etc.).
ByteStreams implements the ConnectTo trait for any pair of AsyncRead and AsyncWrite
streams, handling serialization of JSON-RPC messages to/from newline-delimited JSON.
This is the standard way to communicate with external processes or network connections.
§Use Cases
- Stdio communication: Connect to agents or proxies via stdin/stdout
- Network sockets: TCP, Unix domain sockets, or other stream-based protocols
- Named pipes: Cross-process communication on the same machine
- File I/O: Reading from and writing to file descriptors
§Example
Connecting to an agent via stdio:
use agent_client_protocol::UntypedRole;
use tokio_util::compat::{TokioAsyncReadCompatExt, TokioAsyncWriteCompatExt};
let component = ByteStreams::new(
tokio::io::stdout().compat_write(),
tokio::io::stdin().compat(),
);
// Use as a component in a connection
agent_client_protocol::UntypedRole.builder()
.name("my-client")
.connect_to(component)
.await?;Fields§
§outgoing: OBOutgoing byte stream (where we write serialized messages)
incoming: IBIncoming byte stream (where we read and parse messages)
Implementations§
Source§impl<OB, IB> ByteStreams<OB, IB>
impl<OB, IB> ByteStreams<OB, IB>
Trait Implementations§
Source§impl<OB, IB, R: Role> ConnectTo<R> for ByteStreams<OB, IB>
impl<OB, IB, R: Role> ConnectTo<R> for ByteStreams<OB, IB>
Source§async fn connect_to(
self,
client: impl ConnectTo<R::Counterpart>,
) -> Result<(), Error>
async fn connect_to( self, client: impl ConnectTo<R::Counterpart>, ) -> Result<(), Error>
Serve this component by forwarding to a client component. Read more
Auto Trait Implementations§
impl<OB, IB> Freeze for ByteStreams<OB, IB>
impl<OB, IB> RefUnwindSafe for ByteStreams<OB, IB>where
OB: RefUnwindSafe,
IB: RefUnwindSafe,
impl<OB, IB> Send for ByteStreams<OB, IB>
impl<OB, IB> Sync for ByteStreams<OB, IB>
impl<OB, IB> Unpin for ByteStreams<OB, IB>
impl<OB, IB> UnsafeUnpin for ByteStreams<OB, IB>where
OB: UnsafeUnpin,
IB: UnsafeUnpin,
impl<OB, IB> UnwindSafe for ByteStreams<OB, IB>where
OB: UnwindSafe,
IB: UnwindSafe,
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