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