This is a Rust library with fixed-size buffers, useful for network protocol parsers and file parsers.
forbid(unsafe_code)stdasync-std-feature, futures-io, smol-feature, or tokio.shift() periodically
to move unread bytes to the front of the buffer.Read and handle requests from a remote client: ```rust use fixedbuffer::{deframeline, FixedBuf}; use std::io::Error; use std::net::TcpStream;
fn handleconn(mut tcpstream: TcpStream) -> Result<(), Error> {
let mut buf: FixedBuf<4096> = FixedBuf::new();
loop {
// Read a line
// and leave leftover bytes in buf.
let linebytes = match buf.readframe(
&mut tcpstream, deframeline)? {
Some(linebytes) => linebytes,
None => return Ok(()),
};
let request = Request::parse(linebytes)?;
handlerequest(request)?;
}
}
``
For a complete example, see
[tests/server.rs`](https://gitlab.com/leonhard-llc/fixed-buffer-rs/-/blob/main/fixed-buffer/tests/server.rs).
Read and process records: ```rust use fixed_buffer::FixedBuf; use std::io::{Error, ErrorKind, Read}; use std::net::TcpStream;
fn tryprocessrecord(b: &[u8]) -> Result
fn readandprocess
The From<[u8; SIZE]> implementation is useful in tests. Example:
rust
use core::convert::From;
assert_eq!(3, FixedBuf::from(*b"abc").len());
bytesbuf_redux, circular buffer supportstd::io::BufReaderstd::io::BufWriterstatic-buffer, updated in 2016block-buffer, for processing fixed-length blocks of dataarrayvec, vector with fixed capacity.ReadWriteChain and ReadWriteTake to new
read-write-ext crate.From<&[u8]>write_bytes to take AsRef<[u8]>try_read_exact to read_and_copy_exact.try_read_bytes to try_read_exact.empty, filled, read_byte, read_bytes, try_parse, and write_str.deframe to allow consuming bytes without returning a framewrite_bytes to write as many bytes as it can,
and return new NoWritableSpace error only when it cannot write any bytes.
Remove NotEnoughSpaceError. The method now behaves like std::io::Write::write.From<NotEnoughSpaceError> and From<MalformedInputError> for String.Older changelog entries
FixedBuf<1024>.new arg.capacity.Copy impl.writable return type to &mut [u8].read_byte,
try_read_byte,
try_read_bytes,
try_read_exact,
try_parse.UnwindSafedeframe
and
mem,
needed by AsyncFixedBuf::read_frame.fixed_buffer_tokio.copy_once_from,
read_block,
ReadWriteChain,
and
ReadWriteTake.FixedBuf::escape_ascii.filled
constructor.read_delimited
to return Option<&[u8]>, for clean EOF handling.clear().FixedBuf<[u8; 42]>.AsRef<[u8]> + AsMut<[u8]> value for internal memory:
[u8; N]Box<[u8; N]>&mut [u8]Vec<u8>new_with_mem to new.
Use FixedBuf::default() to construct any FixedBuf<T: Default>, which includes
arrays of sizes up to 32.docs.rs.buf.slice(buf.read_frame(&mut reader, deframe_crlf))frame_copy_iter function.
Because of borrowing rules, this function must return non-borrowed (allocated and copied) data.Cargo.toml and bump version number.../release.shLicense: Apache-2.0