vector/codecs/decoding/
config.rs

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