pub mod codec;
pub mod constants;
pub mod errors;
pub mod frame;
pub mod receiver;
pub mod sender;
pub mod sizing;
pub use codec::{
build_oversized_frames, sha256_digest, split_string_by_byte_size, utf8_byte_len,
BuiltOversizedFrames, OversizedSenderOptions,
};
pub use constants::*;
pub use errors::OversizedTransferError;
pub use frame::{progress_token_string, CompletionMode, OversizedFrame};
pub use receiver::{OversizedTransferReceiver, TransferPolicy};
pub use sender::send_oversized_transfer;
pub use sizing::{measure_published_event_size, resolve_safe_chunk_size};
#[derive(Debug, Clone)]
#[non_exhaustive]
pub struct OversizedTransferConfig {
pub enabled: bool,
pub threshold: usize,
pub chunk_size: usize,
pub max_transfer_bytes: u64,
pub max_transfer_chunks: u64,
pub max_concurrent_transfers: usize,
pub transfer_timeout_ms: u64,
pub max_out_of_order_window: u64,
pub max_out_of_order_chunks: usize,
pub accept_timeout_ms: u64,
}
impl Default for OversizedTransferConfig {
fn default() -> Self {
Self {
enabled: true,
threshold: DEFAULT_OVERSIZED_THRESHOLD,
chunk_size: DEFAULT_CHUNK_SIZE,
max_transfer_bytes: DEFAULT_MAX_TRANSFER_BYTES,
max_transfer_chunks: DEFAULT_MAX_TRANSFER_CHUNKS,
max_concurrent_transfers: DEFAULT_MAX_CONCURRENT_TRANSFERS,
transfer_timeout_ms: DEFAULT_TRANSFER_TIMEOUT_MS,
max_out_of_order_window: DEFAULT_MAX_OUT_OF_ORDER_WINDOW,
max_out_of_order_chunks: DEFAULT_MAX_OUT_OF_ORDER_CHUNKS,
accept_timeout_ms: DEFAULT_ACCEPT_TIMEOUT_MS,
}
}
}
impl OversizedTransferConfig {
pub fn enabled() -> Self {
Self {
enabled: true,
..Self::default()
}
}
pub fn with_enabled(mut self, enabled: bool) -> Self {
self.enabled = enabled;
self
}
pub fn with_threshold(mut self, threshold: usize) -> Self {
self.threshold = threshold;
self
}
pub fn with_chunk_size(mut self, chunk_size: usize) -> Self {
self.chunk_size = chunk_size;
self
}
pub fn with_max_transfer_bytes(mut self, max: u64) -> Self {
self.max_transfer_bytes = max;
self
}
pub fn with_max_transfer_chunks(mut self, max: u64) -> Self {
self.max_transfer_chunks = max;
self
}
pub fn with_max_concurrent_transfers(mut self, max: usize) -> Self {
self.max_concurrent_transfers = max;
self
}
pub fn with_transfer_timeout_ms(mut self, ms: u64) -> Self {
self.transfer_timeout_ms = ms;
self
}
pub fn with_max_out_of_order_window(mut self, window: u64) -> Self {
self.max_out_of_order_window = window;
self
}
pub fn with_max_out_of_order_chunks(mut self, max: usize) -> Self {
self.max_out_of_order_chunks = max;
self
}
pub fn with_accept_timeout_ms(mut self, ms: u64) -> Self {
self.accept_timeout_ms = ms;
self
}
}
impl From<&OversizedTransferConfig> for TransferPolicy {
fn from(config: &OversizedTransferConfig) -> Self {
TransferPolicy {
max_transfer_bytes: config.max_transfer_bytes,
max_transfer_chunks: config.max_transfer_chunks,
max_concurrent_transfers: config.max_concurrent_transfers,
max_out_of_order_window: config.max_out_of_order_window,
max_out_of_order_chunks: config.max_out_of_order_chunks,
transfer_timeout_ms: config.transfer_timeout_ms,
}
}
}