async-prost

Async access to prost-encoded item stream, highly inspected(copied) by/from async-bincode. Could be used with tokio-tower to build TCP applications with prost encoded messages.

Usage:

```rust

[derive(Clone, PartialEq, Message)]

pub struct Event { #[prost(bytes = "bytes", tag = "1")] pub id: Bytes, #[prost(bytes = "bytes", tag = "2")] pub data: Bytes, }

let echo = TcpListener::bind("127.0.0.1:0").await.unwrap(); let addr = echo.local_addr().unwrap();

tokio::spawn(async move { let (stream, ) = echo.accept().await.unwrap(); let mut stream = AsyncProstStream::<_, Event, Event, _>::from(stream).forasync(); let (r, w) = stream.tcp_split(); r.forward(w).await.unwrap(); });

let stream = TcpStream::connect(&addr).await.unwrap(); let mut client = AsyncProstStream::<_, Event, Event, _>::from(stream).forasync(); let event = Event { id: Bytes::fromstatic(b"1234"), data: Bytes::fromstatic(b"hello world"), }; client.send(event.clone()).await.unwrap(); asserteq!(client.next().await.unwrap().unwrap(), event);

let event = Event { id: Bytes::fromstatic(b"1235"), data: Bytes::fromstatic(b"goodbye world"), }; client.send(event.clone()).await.unwrap(); assert_eq!(client.next().await.unwrap().unwrap(), event); drop(client); ```

See tests for more examples.

Have fun with this crate!

License

This project is distributed under the terms of MIT.

See LICENSE for details.

Copyright 2021 Tyr Chen