vector/codecs/decoding/
config.rs

1use serde::{Deserialize, Serialize};
2use vector_lib::{
3    codecs::decoding::{DeserializerConfig, FramingConfig},
4    config::LogNamespace,
5};
6
7use crate::codecs::Decoder;
8
9/// Config used to build a `Decoder`.
10#[derive(Debug, Clone, Deserialize, Serialize)]
11pub struct DecodingConfig {
12    /// The framing config.
13    framing: FramingConfig,
14    /// The decoding config.
15    decoding: DeserializerConfig,
16    /// The namespace used when decoding.
17    log_namespace: LogNamespace,
18}
19
20impl DecodingConfig {
21    /// Creates a new `DecodingConfig` with the provided `FramingConfig` and
22    /// `DeserializerConfig`.
23    pub const fn new(
24        framing: FramingConfig,
25        decoding: DeserializerConfig,
26        log_namespace: LogNamespace,
27    ) -> Self {
28        Self {
29            framing,
30            decoding,
31            log_namespace,
32        }
33    }
34
35    /// Get the decoding configuration.
36    pub const fn config(&self) -> &DeserializerConfig {
37        &self.decoding
38    }
39
40    /// Get the framing configuration.
41    pub const fn framing(&self) -> &FramingConfig {
42        &self.framing
43    }
44
45    /// Builds a `Decoder` from the provided configuration.
46    pub fn build(&self) -> vector_lib::Result<Decoder> {
47        // Build the framer.
48        let framer = self.framing.build();
49
50        // Build the deserializer.
51        let deserializer = self.decoding.build()?;
52
53        Ok(Decoder::new(framer, deserializer).with_log_namespace(self.log_namespace))
54    }
55}