Skip to main content

nominal_api_conjure/conjure/objects/ingest/api/
ingest_options.rs

1use conjure_object::serde::{ser, de};
2use conjure_object::serde::ser::SerializeMap as SerializeMap_;
3use conjure_object::private::{UnionField_, UnionTypeField_};
4use std::fmt;
5#[derive(Debug, Clone, conjure_object::private::DeriveWith)]
6#[derive_with(PartialEq, Eq, PartialOrd, Ord, Hash)]
7pub enum IngestOptions {
8    Dataflash(super::DataflashOpts),
9    McapProtobufTimeseries(super::McapProtobufTimeseriesOpts),
10    JournalJson(super::JournalJsonOpts),
11    Csv(super::CsvOpts),
12    Parquet(super::ParquetOpts),
13    #[deprecated(
14        note = "Legacy Video-entity ingest. Use videoV2, which ingests video as a channel on a dataset."
15    )]
16    Video(super::VideoOpts),
17    VideoV2(super::VideoOptsV2),
18    Containerized(super::ContainerizedOpts),
19    AvroStream(super::AvroStreamOpts),
20    PointCloud(super::PointCloudOpts),
21    /// An unknown variant.
22    Unknown(Unknown),
23}
24impl ser::Serialize for IngestOptions {
25    fn serialize<S>(&self, s: S) -> Result<S::Ok, S::Error>
26    where
27        S: ser::Serializer,
28    {
29        let mut map = s.serialize_map(Some(2))?;
30        match self {
31            IngestOptions::Dataflash(value) => {
32                map.serialize_entry(&"type", &"dataflash")?;
33                map.serialize_entry(&"dataflash", value)?;
34            }
35            IngestOptions::McapProtobufTimeseries(value) => {
36                map.serialize_entry(&"type", &"mcapProtobufTimeseries")?;
37                map.serialize_entry(&"mcapProtobufTimeseries", value)?;
38            }
39            IngestOptions::JournalJson(value) => {
40                map.serialize_entry(&"type", &"journalJson")?;
41                map.serialize_entry(&"journalJson", value)?;
42            }
43            IngestOptions::Csv(value) => {
44                map.serialize_entry(&"type", &"csv")?;
45                map.serialize_entry(&"csv", value)?;
46            }
47            IngestOptions::Parquet(value) => {
48                map.serialize_entry(&"type", &"parquet")?;
49                map.serialize_entry(&"parquet", value)?;
50            }
51            #[allow(deprecated)]
52            IngestOptions::Video(value) => {
53                map.serialize_entry(&"type", &"video")?;
54                map.serialize_entry(&"video", value)?;
55            }
56            IngestOptions::VideoV2(value) => {
57                map.serialize_entry(&"type", &"videoV2")?;
58                map.serialize_entry(&"videoV2", value)?;
59            }
60            IngestOptions::Containerized(value) => {
61                map.serialize_entry(&"type", &"containerized")?;
62                map.serialize_entry(&"containerized", value)?;
63            }
64            IngestOptions::AvroStream(value) => {
65                map.serialize_entry(&"type", &"avroStream")?;
66                map.serialize_entry(&"avroStream", value)?;
67            }
68            IngestOptions::PointCloud(value) => {
69                map.serialize_entry(&"type", &"pointCloud")?;
70                map.serialize_entry(&"pointCloud", value)?;
71            }
72            IngestOptions::Unknown(value) => {
73                map.serialize_entry(&"type", &value.type_)?;
74                map.serialize_entry(&value.type_, &value.value)?;
75            }
76        }
77        map.end()
78    }
79}
80impl<'de> de::Deserialize<'de> for IngestOptions {
81    fn deserialize<D>(d: D) -> Result<IngestOptions, D::Error>
82    where
83        D: de::Deserializer<'de>,
84    {
85        d.deserialize_map(Visitor_)
86    }
87}
88struct Visitor_;
89impl<'de> de::Visitor<'de> for Visitor_ {
90    type Value = IngestOptions;
91    fn expecting(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
92        fmt.write_str("union IngestOptions")
93    }
94    fn visit_map<A>(self, mut map: A) -> Result<IngestOptions, A::Error>
95    where
96        A: de::MapAccess<'de>,
97    {
98        let v = match map.next_key::<UnionField_<Variant_>>()? {
99            Some(UnionField_::Type) => {
100                let variant = map.next_value()?;
101                let key = map.next_key()?;
102                match (variant, key) {
103                    (Variant_::Dataflash, Some(Variant_::Dataflash)) => {
104                        let value = map.next_value()?;
105                        IngestOptions::Dataflash(value)
106                    }
107                    (
108                        Variant_::McapProtobufTimeseries,
109                        Some(Variant_::McapProtobufTimeseries),
110                    ) => {
111                        let value = map.next_value()?;
112                        IngestOptions::McapProtobufTimeseries(value)
113                    }
114                    (Variant_::JournalJson, Some(Variant_::JournalJson)) => {
115                        let value = map.next_value()?;
116                        IngestOptions::JournalJson(value)
117                    }
118                    (Variant_::Csv, Some(Variant_::Csv)) => {
119                        let value = map.next_value()?;
120                        IngestOptions::Csv(value)
121                    }
122                    (Variant_::Parquet, Some(Variant_::Parquet)) => {
123                        let value = map.next_value()?;
124                        IngestOptions::Parquet(value)
125                    }
126                    #[allow(deprecated)]
127                    (Variant_::Video, Some(Variant_::Video)) => {
128                        let value = map.next_value()?;
129                        IngestOptions::Video(value)
130                    }
131                    (Variant_::VideoV2, Some(Variant_::VideoV2)) => {
132                        let value = map.next_value()?;
133                        IngestOptions::VideoV2(value)
134                    }
135                    (Variant_::Containerized, Some(Variant_::Containerized)) => {
136                        let value = map.next_value()?;
137                        IngestOptions::Containerized(value)
138                    }
139                    (Variant_::AvroStream, Some(Variant_::AvroStream)) => {
140                        let value = map.next_value()?;
141                        IngestOptions::AvroStream(value)
142                    }
143                    (Variant_::PointCloud, Some(Variant_::PointCloud)) => {
144                        let value = map.next_value()?;
145                        IngestOptions::PointCloud(value)
146                    }
147                    (Variant_::Unknown(type_), Some(Variant_::Unknown(b))) => {
148                        if type_ == b {
149                            let value = map.next_value()?;
150                            IngestOptions::Unknown(Unknown { type_, value })
151                        } else {
152                            return Err(
153                                de::Error::invalid_value(de::Unexpected::Str(&type_), &&*b),
154                            )
155                        }
156                    }
157                    (variant, Some(key)) => {
158                        return Err(
159                            de::Error::invalid_value(
160                                de::Unexpected::Str(key.as_str()),
161                                &variant.as_str(),
162                            ),
163                        );
164                    }
165                    (variant, None) => {
166                        return Err(de::Error::missing_field(variant.as_str()));
167                    }
168                }
169            }
170            Some(UnionField_::Value(variant)) => {
171                let value = match &variant {
172                    Variant_::Dataflash => {
173                        let value = map.next_value()?;
174                        IngestOptions::Dataflash(value)
175                    }
176                    Variant_::McapProtobufTimeseries => {
177                        let value = map.next_value()?;
178                        IngestOptions::McapProtobufTimeseries(value)
179                    }
180                    Variant_::JournalJson => {
181                        let value = map.next_value()?;
182                        IngestOptions::JournalJson(value)
183                    }
184                    Variant_::Csv => {
185                        let value = map.next_value()?;
186                        IngestOptions::Csv(value)
187                    }
188                    Variant_::Parquet => {
189                        let value = map.next_value()?;
190                        IngestOptions::Parquet(value)
191                    }
192                    Variant_::Video => {
193                        let value = map.next_value()?;
194                        #[allow(deprecated)] IngestOptions::Video(value)
195                    }
196                    Variant_::VideoV2 => {
197                        let value = map.next_value()?;
198                        IngestOptions::VideoV2(value)
199                    }
200                    Variant_::Containerized => {
201                        let value = map.next_value()?;
202                        IngestOptions::Containerized(value)
203                    }
204                    Variant_::AvroStream => {
205                        let value = map.next_value()?;
206                        IngestOptions::AvroStream(value)
207                    }
208                    Variant_::PointCloud => {
209                        let value = map.next_value()?;
210                        IngestOptions::PointCloud(value)
211                    }
212                    Variant_::Unknown(type_) => {
213                        let value = map.next_value()?;
214                        IngestOptions::Unknown(Unknown {
215                            type_: type_.clone(),
216                            value,
217                        })
218                    }
219                };
220                if map.next_key::<UnionTypeField_>()?.is_none() {
221                    return Err(de::Error::missing_field("type"));
222                }
223                let type_variant = map.next_value::<Variant_>()?;
224                if variant != type_variant {
225                    return Err(
226                        de::Error::invalid_value(
227                            de::Unexpected::Str(type_variant.as_str()),
228                            &variant.as_str(),
229                        ),
230                    );
231                }
232                value
233            }
234            None => return Err(de::Error::missing_field("type")),
235        };
236        if map.next_key::<UnionField_<Variant_>>()?.is_some() {
237            return Err(de::Error::invalid_length(3, &"type and value fields"));
238        }
239        Ok(v)
240    }
241}
242#[derive(PartialEq)]
243enum Variant_ {
244    Dataflash,
245    McapProtobufTimeseries,
246    JournalJson,
247    Csv,
248    Parquet,
249    Video,
250    VideoV2,
251    Containerized,
252    AvroStream,
253    PointCloud,
254    Unknown(Box<str>),
255}
256impl Variant_ {
257    fn as_str(&self) -> &'static str {
258        match *self {
259            Variant_::Dataflash => "dataflash",
260            Variant_::McapProtobufTimeseries => "mcapProtobufTimeseries",
261            Variant_::JournalJson => "journalJson",
262            Variant_::Csv => "csv",
263            Variant_::Parquet => "parquet",
264            Variant_::Video => "video",
265            Variant_::VideoV2 => "videoV2",
266            Variant_::Containerized => "containerized",
267            Variant_::AvroStream => "avroStream",
268            Variant_::PointCloud => "pointCloud",
269            Variant_::Unknown(_) => "unknown variant",
270        }
271    }
272}
273impl<'de> de::Deserialize<'de> for Variant_ {
274    fn deserialize<D>(d: D) -> Result<Variant_, D::Error>
275    where
276        D: de::Deserializer<'de>,
277    {
278        d.deserialize_str(VariantVisitor_)
279    }
280}
281struct VariantVisitor_;
282impl<'de> de::Visitor<'de> for VariantVisitor_ {
283    type Value = Variant_;
284    fn expecting(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
285        fmt.write_str("string")
286    }
287    fn visit_str<E>(self, value: &str) -> Result<Variant_, E>
288    where
289        E: de::Error,
290    {
291        let v = match value {
292            "dataflash" => Variant_::Dataflash,
293            "mcapProtobufTimeseries" => Variant_::McapProtobufTimeseries,
294            "journalJson" => Variant_::JournalJson,
295            "csv" => Variant_::Csv,
296            "parquet" => Variant_::Parquet,
297            "video" => Variant_::Video,
298            "videoV2" => Variant_::VideoV2,
299            "containerized" => Variant_::Containerized,
300            "avroStream" => Variant_::AvroStream,
301            "pointCloud" => Variant_::PointCloud,
302            value => Variant_::Unknown(value.to_string().into_boxed_str()),
303        };
304        Ok(v)
305    }
306}
307///An unknown variant of the IngestOptions union.
308#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
309pub struct Unknown {
310    type_: Box<str>,
311    value: conjure_object::Any,
312}
313impl Unknown {
314    /// Returns the unknown variant's type name.
315    #[inline]
316    pub fn type_(&self) -> &str {
317        &self.type_
318    }
319}