use vector_lib::codecs::{encoding::SerializerConfig, CsvSerializerConfig, JsonSerializerConfig};
use vector_lib::configurable::configurable_component;
use crate::codecs::{EncodingConfig, Transformer};
#[configurable_component]
#[derive(Clone, Debug)]
#[serde(tag = "codec", rename_all = "snake_case")]
#[configurable(metadata(docs::enum_tag_description = "The codec to use for encoding events."))]
pub(super) enum DatabendSerializerConfig {
Csv(
CsvSerializerConfig,
),
Json(
JsonSerializerConfig,
),
}
impl From<DatabendSerializerConfig> for SerializerConfig {
fn from(config: DatabendSerializerConfig) -> Self {
match config {
DatabendSerializerConfig::Csv(config) => Self::Csv(config),
DatabendSerializerConfig::Json(config) => Self::Json(config),
}
}
}
impl Default for DatabendSerializerConfig {
fn default() -> Self {
Self::Json(JsonSerializerConfig::default())
}
}
#[configurable_component]
#[derive(Clone, Debug, Default)]
#[configurable(description = "Configures how events are encoded into raw bytes.")]
pub struct DatabendEncodingConfig {
#[serde(flatten)]
encoding: DatabendSerializerConfig,
#[serde(flatten)]
transformer: Transformer,
}
impl From<DatabendEncodingConfig> for EncodingConfig {
fn from(encoding: DatabendEncodingConfig) -> Self {
Self::new(encoding.encoding.into(), encoding.transformer)
}
}
impl DatabendEncodingConfig {
pub(super) const fn config(&self) -> &DatabendSerializerConfig {
&self.encoding
}
}
#[configurable_component]
#[derive(Clone, Debug)]
#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
#[configurable(metadata(docs::enum_tag_description = "How to handle missing fields for NDJson."))]
pub enum DatabendMissingFieldAS {
Error,
Null,
FieldDefault,
TypeDefault,
}
impl Default for DatabendMissingFieldAS {
fn default() -> Self {
Self::Null
}
}
impl DatabendMissingFieldAS {
pub(super) const fn as_str(&self) -> &'static str {
match self {
Self::Error => "ERROR",
Self::Null => "NULL",
Self::FieldDefault => "FIELD_DEFAULT",
Self::TypeDefault => "TYPE_DEFAULT",
}
}
}