datadog_api_client/datadogV2/model/
model_observability_pipeline_splunk_tcp_source.rs1use serde::de::{Error, MapAccess, Visitor};
5use serde::{Deserialize, Deserializer, Serialize};
6use serde_with::skip_serializing_none;
7use std::fmt::{self, Formatter};
8
9#[non_exhaustive]
13#[skip_serializing_none]
14#[derive(Clone, Debug, PartialEq, Serialize)]
15pub struct ObservabilityPipelineSplunkTcpSource {
16 #[serde(rename = "id")]
18 pub id: String,
19 #[serde(rename = "tls")]
21 pub tls: Option<crate::datadogV2::model::ObservabilityPipelineTls>,
22 #[serde(rename = "type")]
24 pub type_: crate::datadogV2::model::ObservabilityPipelineSplunkTcpSourceType,
25 #[serde(flatten)]
26 pub additional_properties: std::collections::BTreeMap<String, serde_json::Value>,
27 #[serde(skip)]
28 #[serde(default)]
29 pub(crate) _unparsed: bool,
30}
31
32impl ObservabilityPipelineSplunkTcpSource {
33 pub fn new(
34 id: String,
35 type_: crate::datadogV2::model::ObservabilityPipelineSplunkTcpSourceType,
36 ) -> ObservabilityPipelineSplunkTcpSource {
37 ObservabilityPipelineSplunkTcpSource {
38 id,
39 tls: None,
40 type_,
41 additional_properties: std::collections::BTreeMap::new(),
42 _unparsed: false,
43 }
44 }
45
46 pub fn tls(mut self, value: crate::datadogV2::model::ObservabilityPipelineTls) -> Self {
47 self.tls = Some(value);
48 self
49 }
50
51 pub fn additional_properties(
52 mut self,
53 value: std::collections::BTreeMap<String, serde_json::Value>,
54 ) -> Self {
55 self.additional_properties = value;
56 self
57 }
58}
59
60impl<'de> Deserialize<'de> for ObservabilityPipelineSplunkTcpSource {
61 fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
62 where
63 D: Deserializer<'de>,
64 {
65 struct ObservabilityPipelineSplunkTcpSourceVisitor;
66 impl<'a> Visitor<'a> for ObservabilityPipelineSplunkTcpSourceVisitor {
67 type Value = ObservabilityPipelineSplunkTcpSource;
68
69 fn expecting(&self, f: &mut Formatter<'_>) -> fmt::Result {
70 f.write_str("a mapping")
71 }
72
73 fn visit_map<M>(self, mut map: M) -> Result<Self::Value, M::Error>
74 where
75 M: MapAccess<'a>,
76 {
77 let mut id: Option<String> = None;
78 let mut tls: Option<crate::datadogV2::model::ObservabilityPipelineTls> = None;
79 let mut type_: Option<
80 crate::datadogV2::model::ObservabilityPipelineSplunkTcpSourceType,
81 > = None;
82 let mut additional_properties: std::collections::BTreeMap<
83 String,
84 serde_json::Value,
85 > = std::collections::BTreeMap::new();
86 let mut _unparsed = false;
87
88 while let Some((k, v)) = map.next_entry::<String, serde_json::Value>()? {
89 match k.as_str() {
90 "id" => {
91 id = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
92 }
93 "tls" => {
94 if v.is_null() {
95 continue;
96 }
97 tls = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
98 }
99 "type" => {
100 type_ = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
101 if let Some(ref _type_) = type_ {
102 match _type_ {
103 crate::datadogV2::model::ObservabilityPipelineSplunkTcpSourceType::UnparsedObject(_type_) => {
104 _unparsed = true;
105 },
106 _ => {}
107 }
108 }
109 }
110 &_ => {
111 if let Ok(value) = serde_json::from_value(v.clone()) {
112 additional_properties.insert(k, value);
113 }
114 }
115 }
116 }
117 let id = id.ok_or_else(|| M::Error::missing_field("id"))?;
118 let type_ = type_.ok_or_else(|| M::Error::missing_field("type_"))?;
119
120 let content = ObservabilityPipelineSplunkTcpSource {
121 id,
122 tls,
123 type_,
124 additional_properties,
125 _unparsed,
126 };
127
128 Ok(content)
129 }
130 }
131
132 deserializer.deserialize_any(ObservabilityPipelineSplunkTcpSourceVisitor)
133 }
134}