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