codecs/decoding/
config.rs

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