1
Fork 0

moved serialization to encoder

This commit is contained in:
Andy Killorin 2025-02-01 16:24:10 -05:00
parent 5d88a32095
commit 91ed6eeb14
Signed by: ank
GPG key ID: 23F9463ECB67FE8C

View file

@ -1,13 +1,9 @@
#![feature(async_closure)] #![feature(async_closure)]
use std::pin::{pin, Pin};
use anyhow::{Context, Result}; use anyhow::{Context, Result};
use common::{Command, Response, BAUDRATE}; use common::{Command, Response, BAUDRATE};
use framed::BoxPayload;
use framed_codec::FramedCodec; use framed_codec::FramedCodec;
use futures::{SinkExt, StreamExt}; use futures::{SinkExt, StreamExt};
use tokio::io::AsyncBufReadExt;
use tokio_serial::SerialPortBuilderExt; use tokio_serial::SerialPortBuilderExt;
use tokio_util::codec::Framed; use tokio_util::codec::Framed;
@ -25,17 +21,11 @@ async fn main() -> Result<()> {
Ok(postcard::from_bytes::<Response>(&data.ok().context("decode err")?)?) Ok(postcard::from_bytes::<Response>(&data.ok().context("decode err")?)?)
}); });
let mut write = write.with(move |data: Command| {
let data = postcard::to_stdvec(&data).unwrap();
async move {Ok(data)}
});
while let Some(data) = read.next().await { while let Some(data) = read.next().await {
dbg!(data?); dbg!(data?);
write.send(Command::Enable).await?;
write.send(Command::Enable).await;
} }
Ok(()) Ok(())