nominal_api/conjure/objects/scout/compute/api/
compute_node.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 ComputeNode {
8 Boolean(Box<super::BooleanSeries>),
9 Enum(Box<super::EnumSeries>),
10 Numeric(Box<super::NumericSeries>),
11 Log(Box<super::LogSeries>),
12 Ranges(Box<super::RangeSeries>),
13 Array(Box<super::ArraySeries>),
14 Struct(Box<super::StructSeries>),
15 CurveFit(super::CurveFit),
16 Video(super::Reference),
17 #[deprecated(note = "wrap raw references in a typed compute node.")]
18 Raw(super::Reference),
19 Unknown(Unknown),
21}
22impl ser::Serialize for ComputeNode {
23 fn serialize<S>(&self, s: S) -> Result<S::Ok, S::Error>
24 where
25 S: ser::Serializer,
26 {
27 let mut map = s.serialize_map(Some(2))?;
28 match self {
29 ComputeNode::Boolean(value) => {
30 map.serialize_entry(&"type", &"boolean")?;
31 map.serialize_entry(&"boolean", value)?;
32 }
33 ComputeNode::Enum(value) => {
34 map.serialize_entry(&"type", &"enum")?;
35 map.serialize_entry(&"enum", value)?;
36 }
37 ComputeNode::Numeric(value) => {
38 map.serialize_entry(&"type", &"numeric")?;
39 map.serialize_entry(&"numeric", value)?;
40 }
41 ComputeNode::Log(value) => {
42 map.serialize_entry(&"type", &"log")?;
43 map.serialize_entry(&"log", value)?;
44 }
45 ComputeNode::Ranges(value) => {
46 map.serialize_entry(&"type", &"ranges")?;
47 map.serialize_entry(&"ranges", value)?;
48 }
49 ComputeNode::Array(value) => {
50 map.serialize_entry(&"type", &"array")?;
51 map.serialize_entry(&"array", value)?;
52 }
53 ComputeNode::Struct(value) => {
54 map.serialize_entry(&"type", &"struct")?;
55 map.serialize_entry(&"struct", value)?;
56 }
57 ComputeNode::CurveFit(value) => {
58 map.serialize_entry(&"type", &"curveFit")?;
59 map.serialize_entry(&"curveFit", value)?;
60 }
61 ComputeNode::Video(value) => {
62 map.serialize_entry(&"type", &"video")?;
63 map.serialize_entry(&"video", value)?;
64 }
65 #[allow(deprecated)]
66 ComputeNode::Raw(value) => {
67 map.serialize_entry(&"type", &"raw")?;
68 map.serialize_entry(&"raw", value)?;
69 }
70 ComputeNode::Unknown(value) => {
71 map.serialize_entry(&"type", &value.type_)?;
72 map.serialize_entry(&value.type_, &value.value)?;
73 }
74 }
75 map.end()
76 }
77}
78impl<'de> de::Deserialize<'de> for ComputeNode {
79 fn deserialize<D>(d: D) -> Result<ComputeNode, D::Error>
80 where
81 D: de::Deserializer<'de>,
82 {
83 d.deserialize_map(Visitor_)
84 }
85}
86struct Visitor_;
87impl<'de> de::Visitor<'de> for Visitor_ {
88 type Value = ComputeNode;
89 fn expecting(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
90 fmt.write_str("union ComputeNode")
91 }
92 fn visit_map<A>(self, mut map: A) -> Result<ComputeNode, A::Error>
93 where
94 A: de::MapAccess<'de>,
95 {
96 let v = match map.next_key::<UnionField_<Variant_>>()? {
97 Some(UnionField_::Type) => {
98 let variant = map.next_value()?;
99 let key = map.next_key()?;
100 match (variant, key) {
101 (Variant_::Boolean, Some(Variant_::Boolean)) => {
102 let value = map.next_value()?;
103 ComputeNode::Boolean(value)
104 }
105 (Variant_::Enum, Some(Variant_::Enum)) => {
106 let value = map.next_value()?;
107 ComputeNode::Enum(value)
108 }
109 (Variant_::Numeric, Some(Variant_::Numeric)) => {
110 let value = map.next_value()?;
111 ComputeNode::Numeric(value)
112 }
113 (Variant_::Log, Some(Variant_::Log)) => {
114 let value = map.next_value()?;
115 ComputeNode::Log(value)
116 }
117 (Variant_::Ranges, Some(Variant_::Ranges)) => {
118 let value = map.next_value()?;
119 ComputeNode::Ranges(value)
120 }
121 (Variant_::Array, Some(Variant_::Array)) => {
122 let value = map.next_value()?;
123 ComputeNode::Array(value)
124 }
125 (Variant_::Struct, Some(Variant_::Struct)) => {
126 let value = map.next_value()?;
127 ComputeNode::Struct(value)
128 }
129 (Variant_::CurveFit, Some(Variant_::CurveFit)) => {
130 let value = map.next_value()?;
131 ComputeNode::CurveFit(value)
132 }
133 (Variant_::Video, Some(Variant_::Video)) => {
134 let value = map.next_value()?;
135 ComputeNode::Video(value)
136 }
137 #[allow(deprecated)]
138 (Variant_::Raw, Some(Variant_::Raw)) => {
139 let value = map.next_value()?;
140 ComputeNode::Raw(value)
141 }
142 (Variant_::Unknown(type_), Some(Variant_::Unknown(b))) => {
143 if type_ == b {
144 let value = map.next_value()?;
145 ComputeNode::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_::Boolean => {
168 let value = map.next_value()?;
169 ComputeNode::Boolean(value)
170 }
171 Variant_::Enum => {
172 let value = map.next_value()?;
173 ComputeNode::Enum(value)
174 }
175 Variant_::Numeric => {
176 let value = map.next_value()?;
177 ComputeNode::Numeric(value)
178 }
179 Variant_::Log => {
180 let value = map.next_value()?;
181 ComputeNode::Log(value)
182 }
183 Variant_::Ranges => {
184 let value = map.next_value()?;
185 ComputeNode::Ranges(value)
186 }
187 Variant_::Array => {
188 let value = map.next_value()?;
189 ComputeNode::Array(value)
190 }
191 Variant_::Struct => {
192 let value = map.next_value()?;
193 ComputeNode::Struct(value)
194 }
195 Variant_::CurveFit => {
196 let value = map.next_value()?;
197 ComputeNode::CurveFit(value)
198 }
199 Variant_::Video => {
200 let value = map.next_value()?;
201 ComputeNode::Video(value)
202 }
203 Variant_::Raw => {
204 let value = map.next_value()?;
205 #[allow(deprecated)] ComputeNode::Raw(value)
206 }
207 Variant_::Unknown(type_) => {
208 let value = map.next_value()?;
209 ComputeNode::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 Boolean,
240 Enum,
241 Numeric,
242 Log,
243 Ranges,
244 Array,
245 Struct,
246 CurveFit,
247 Video,
248 Raw,
249 Unknown(Box<str>),
250}
251impl Variant_ {
252 fn as_str(&self) -> &'static str {
253 match *self {
254 Variant_::Boolean => "boolean",
255 Variant_::Enum => "enum",
256 Variant_::Numeric => "numeric",
257 Variant_::Log => "log",
258 Variant_::Ranges => "ranges",
259 Variant_::Array => "array",
260 Variant_::Struct => "struct",
261 Variant_::CurveFit => "curveFit",
262 Variant_::Video => "video",
263 Variant_::Raw => "raw",
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 "boolean" => Variant_::Boolean,
288 "enum" => Variant_::Enum,
289 "numeric" => Variant_::Numeric,
290 "log" => Variant_::Log,
291 "ranges" => Variant_::Ranges,
292 "array" => Variant_::Array,
293 "struct" => Variant_::Struct,
294 "curveFit" => Variant_::CurveFit,
295 "video" => Variant_::Video,
296 "raw" => Variant_::Raw,
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}