5 releases (3 breaking)

0.4.0 May 30, 2022
0.3.0 Nov 9, 2021
0.2.1 Sep 18, 2021
0.2.0 Apr 8, 2021
0.1.0 Apr 7, 2021

#1486 in Development tools

Download history 46/week @ 2023-11-18 30/week @ 2023-11-25 20/week @ 2023-12-02 35/week @ 2023-12-09 38/week @ 2023-12-16 32/week @ 2023-12-23 9/week @ 2023-12-30 30/week @ 2024-01-06 43/week @ 2024-01-13 15/week @ 2024-01-20 24/week @ 2024-01-27 2/week @ 2024-02-03 64/week @ 2024-02-10 131/week @ 2024-02-17 68/week @ 2024-02-24 50/week @ 2024-03-02

313 downloads per month

MIT license

28KB
604 lines

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:

#[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).for_async();
    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).for_async();
let event = Event {
    id: Bytes::from_static(b"1234"),
    data: Bytes::from_static(b"hello world"),
};
client.send(event.clone()).await.unwrap();
assert_eq!(client.next().await.unwrap().unwrap(), event);

let event = Event {
    id: Bytes::from_static(b"1235"),
    data: Bytes::from_static(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

Dependencies

~4–15MB
~160K SLoC