codecs/encoding/chunking/mod.rs
1//! Optional extension for encoding formats to support chunking, used when the sink transport (e.g., UDP) has a payload size limit.
2//!
3//! Chunking allows large encoded events to be split into smaller frames, ensuring compatibility with transports that cannot send large payloads in a single datagram or packet.
4
5mod gelf;
6
7use bytes::Bytes;
8pub use gelf::GelfChunker;
9
10/// Trait for encoding formats that optionally support chunking, for use with sinks that have payload size limits (such as UDP).
11///
12/// Chunking is an extension to the standard `Encoder` trait, allowing large encoded events to be split into multiple frames for transmission.
13pub trait Chunking {
14 /// Chunks the input into frames.
15 fn chunk(&self, bytes: Bytes) -> Result<Vec<Bytes>, vector_common::Error>;
16}
17
18/// Implementations of chunking strategies for supported formats.
19#[derive(Clone, Debug)]
20pub enum Chunker {
21 /// GELF chunking implementation.
22 Gelf(GelfChunker),
23}
24
25impl Chunking for Chunker {
26 fn chunk(&self, bytes: Bytes) -> Result<Vec<Bytes>, vector_common::Error> {
27 match self {
28 Chunker::Gelf(chunker) => chunker.chunk(bytes),
29 }
30 }
31}