converted southbridge -> northbridge to length-data

also divided the pwm clock by ten to align with microseconds
This commit is contained in:
Andy Killorin 2025-02-04 13:54:01 -05:00
commit 1c268bba12
Signed by: ank
GPG key ID: 23F9463ECB67FE8C

View file

@ -1,4 +1,4 @@
use anyhow::anyhow;
use anyhow::{anyhow, Ok};
use common::Command;
use framed::{BoxPayload, FRAME_END_SYMBOL};
use tokio_util::{bytes::BytesMut, codec::{Decoder, Encoder}};
@ -15,26 +15,31 @@ impl FramedCodec {
}
impl Decoder for FramedCodec {
type Item = BoxPayload;
type Error = framed::Error;
type Item = Vec<u8>;
type Error = anyhow::Error;
fn decode(&mut self, src: &mut BytesMut) -> Result<Option<Self::Item>, Self::Error> {
match src.iter().position(|e| *e==FRAME_END_SYMBOL) {
Some(len) => {
let data = src.split_to(len);
Ok(Some(self.codec.decode_to_box(&data)?))
}
None => {
Ok(None)
}
if src.len() < 4 {
return Ok(None);
}
let len = u32::from_be_bytes(src[..4].try_into()?) as usize;
if src.len() < len + 4 {
return Ok(None);
}
let data = src.split_to(len + 4);
let mut out = Vec::new();
out.extend_from_slice(&data[4..]);
Ok(Some(out))
}
}
impl Encoder<Vec<u8>> for FramedCodec {
type Error = framed::Error;
type Error = anyhow::Error;
fn encode(&mut self, item: Vec<u8>, dst: &mut BytesMut) -> Result<(), Self::Error> {
dst.extend_from_slice(&item.len().to_be_bytes());