datadog_api_client/datadogV2/model/
model_observability_pipeline_decoding.rs

1// Unless explicitly stated otherwise all files in this repository are licensed under the Apache-2.0 License.
2// This product includes software developed at Datadog (https://www.datadoghq.com/).
3// Copyright 2019-Present Datadog, Inc.
4
5use serde::{Deserialize, Deserializer, Serialize, Serializer};
6
7#[non_exhaustive]
8#[derive(Clone, Debug, Eq, PartialEq)]
9pub enum ObservabilityPipelineDecoding {
10    DECODE_BYTES,
11    DECODE_GELF,
12    DECODE_JSON,
13    DECODE_SYSLOG,
14    UnparsedObject(crate::datadog::UnparsedObject),
15}
16
17impl ToString for ObservabilityPipelineDecoding {
18    fn to_string(&self) -> String {
19        match self {
20            Self::DECODE_BYTES => String::from("bytes"),
21            Self::DECODE_GELF => String::from("gelf"),
22            Self::DECODE_JSON => String::from("json"),
23            Self::DECODE_SYSLOG => String::from("syslog"),
24            Self::UnparsedObject(v) => v.value.to_string(),
25        }
26    }
27}
28
29impl Serialize for ObservabilityPipelineDecoding {
30    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
31    where
32        S: Serializer,
33    {
34        match self {
35            Self::UnparsedObject(v) => v.serialize(serializer),
36            _ => serializer.serialize_str(self.to_string().as_str()),
37        }
38    }
39}
40
41impl<'de> Deserialize<'de> for ObservabilityPipelineDecoding {
42    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
43    where
44        D: Deserializer<'de>,
45    {
46        let s: String = String::deserialize(deserializer)?;
47        Ok(match s.as_str() {
48            "bytes" => Self::DECODE_BYTES,
49            "gelf" => Self::DECODE_GELF,
50            "json" => Self::DECODE_JSON,
51            "syslog" => Self::DECODE_SYSLOG,
52            _ => Self::UnparsedObject(crate::datadog::UnparsedObject {
53                value: serde_json::Value::String(s.into()),
54            }),
55        })
56    }
57}