Fix stuff

This commit is contained in:
2026-05-13 23:08:21 -07:00
parent db2bf1bffd
commit 08be61966c
11 changed files with 1038 additions and 231 deletions
+4
View File
@@ -8,3 +8,7 @@ roto-runtime = { path = "../runtime" }
tonic = "0.12"
bytes = "1.7"
prost = "0.13"
http-body = "1.0"
http-body-util = "0.1"
tower = "0.4"
futures-util = "0.3"
+49 -1
View File
@@ -1,7 +1,12 @@
use std::marker::PhantomData;
use tonic::codec::{Codec, Decoder, Encoder, DecodeBuf, EncodeBuf};
use bytes::{Buf, BufMut};
use bytes::{Buf, BufMut, Bytes, BytesMut};
use roto_runtime::RotoMessage;
use std::sync::{Arc, Mutex};
use std::pin::Pin;
use std::future::Future;
use std::task::{Context, Poll};
use http_body::Body;
pub struct RotoCodec<T, U> {
_phantom: PhantomData<(T, U)>,
@@ -70,3 +75,46 @@ where
}
}
}
pub struct BufferPool {
pool: Mutex<Vec<BytesMut>>,
default_capacity: usize,
}
impl BufferPool {
pub fn new(default_capacity: usize) -> Self {
Self {
pool: Mutex::new(Vec::new()),
default_capacity,
}
}
pub fn get(&self) -> BytesMut {
self.pool.lock().unwrap().pop().unwrap_or_else(|| BytesMut::with_capacity(self.default_capacity))
}
pub fn put(&self, mut buf: BytesMut) {
buf.clear();
if buf.capacity() >= self.default_capacity {
self.pool.lock().unwrap().push(buf);
}
}
}
pub struct StatusBody(pub(crate) Option<Bytes>);
impl Body for StatusBody {
type Data = Bytes;
type Error = tonic::Status;
fn poll_frame(
mut self: Pin<&mut Self>,
cx: &mut Context<'_>,
) -> Poll<Option<Result<http_body::Frame<Self::Data>, Self::Error>>> {
if let Some(data) = self.0.take() {
Poll::Ready(Some(Ok(http_body::Frame::data(data))))
} else {
Poll::Ready(None)
}
}
}