sausage-plugin part 2: import! with typed clients (sausage_interface::client_rs), TCP endpoints with rpc.endpoint, examples
Part 1 fixes: complete stdout writes, buffered stdin, Rust type names in schemas, enum variant docs, -32603 for serde errors in handlers, crate docs and modules. End-to-end check of a generated consumer through a fake core.
This commit is contained in:
@@ -0,0 +1,29 @@
|
||||
//! Buffered newline framing shared by stdin and endpoint connections.
|
||||
#[cfg(target_os = "wasi")]
|
||||
#[derive(Default)]
|
||||
pub(crate) struct Lines {
|
||||
bytes: Vec<u8>,
|
||||
}
|
||||
#[cfg(target_os = "wasi")]
|
||||
impl Lines {
|
||||
pub(crate) async fn next(
|
||||
&mut self,
|
||||
input: &mut impl wstd::io::AsyncRead,
|
||||
) -> std::io::Result<Option<Vec<u8>>> {
|
||||
loop {
|
||||
if let Some(end) = self.bytes.iter().position(|b| *b == b'\n') {
|
||||
return Ok(Some(self.bytes.drain(..=end).collect()));
|
||||
}
|
||||
let mut buffer = [0; 8192];
|
||||
let count = input.read(&mut buffer).await?;
|
||||
if count == 0 {
|
||||
return Ok(if self.bytes.is_empty() {
|
||||
None
|
||||
} else {
|
||||
Some(std::mem::take(&mut self.bytes))
|
||||
});
|
||||
}
|
||||
self.bytes.extend_from_slice(&buffer[..count]);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user