|
|
@ -13,6 +13,10 @@ type Decompressor<T> = BzDecoder<T>;
|
|
|
|
const DEFER_DROP_SIZE_FLOOR: usize = 1024 * 1024; // 1 MB
|
|
|
|
const DEFER_DROP_SIZE_FLOOR: usize = 1024 * 1024; // 1 MB
|
|
|
|
|
|
|
|
|
|
|
|
/// Serialise this object asynchronously
|
|
|
|
/// Serialise this object asynchronously
|
|
|
|
|
|
|
|
///
|
|
|
|
|
|
|
|
/// # Note
|
|
|
|
|
|
|
|
/// This compresses the output stream.
|
|
|
|
|
|
|
|
/// It cannot be used by `prealloc` read/write functions, as they do not compress.
|
|
|
|
pub async fn write_async<T: Serialize, W>(mut to: W, item: &T) -> eyre::Result<()>
|
|
|
|
pub async fn write_async<T: Serialize, W>(mut to: W, item: &T) -> eyre::Result<()>
|
|
|
|
where W: AsyncWrite + Unpin
|
|
|
|
where W: AsyncWrite + Unpin
|
|
|
|
{
|
|
|
|
{
|
|
|
@ -57,3 +61,29 @@ where W: AsyncWrite + Unpin
|
|
|
|
}
|
|
|
|
}
|
|
|
|
flush_fut.await
|
|
|
|
flush_fut.await
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#[cfg(feature="prealloc")]
|
|
|
|
|
|
|
|
mod prealloc {
|
|
|
|
|
|
|
|
use super::*;
|
|
|
|
|
|
|
|
use std::os::unix::prelude::*;
|
|
|
|
|
|
|
|
/// Write this object as-is to this file descriptor.
|
|
|
|
|
|
|
|
///
|
|
|
|
|
|
|
|
/// # Note
|
|
|
|
|
|
|
|
/// This does not compress like `write_aynsc()` does. It is just a 1-1 dump of the serialisation.
|
|
|
|
|
|
|
|
/// Therefore, `write_prealloc` cannot be used with `read_async()`, and other such things.
|
|
|
|
|
|
|
|
///
|
|
|
|
|
|
|
|
/// `fd` must be a valid *File* descriptor. fallocating and mapping stdout probably won't work
|
|
|
|
|
|
|
|
///
|
|
|
|
|
|
|
|
/// This is a completely synchronous operation. You should use it with `spawn_blocking` et al. to prevent task hangups.
|
|
|
|
|
|
|
|
pub fn write_prealloc<T: Serialize>(fd: impl AsRawFd, item: &T) -> eyre::Result<()>
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
//TODO: serialise `item` to vec.
|
|
|
|
|
|
|
|
//TODO: fallocate() `fd` to size of `vec`
|
|
|
|
|
|
|
|
//TODO: memmap() `fd`
|
|
|
|
|
|
|
|
//TODO: memcpy() vec to map
|
|
|
|
|
|
|
|
//TODO: flush map
|
|
|
|
|
|
|
|
//TODO: `drop!(vec)`
|
|
|
|
|
|
|
|
todo!()
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#[cfg(feature="prealloc")] pub use prealloc::write_prealloc as write_sync_map;
|
|
|
|