risingwave_pb/
source.serde.rs

1use crate::source::*;
2impl serde::Serialize for ConnectorSplit {
3    #[allow(deprecated)]
4    fn serialize<S>(&self, serializer: S) -> std::result::Result<S::Ok, S::Error>
5    where
6        S: serde::Serializer,
7    {
8        use serde::ser::SerializeStruct;
9        let mut len = 0;
10        if !self.split_type.is_empty() {
11            len += 1;
12        }
13        if !self.encoded_split.is_empty() {
14            len += 1;
15        }
16        let mut struct_ser = serializer.serialize_struct("source.ConnectorSplit", len)?;
17        if !self.split_type.is_empty() {
18            struct_ser.serialize_field("splitType", &self.split_type)?;
19        }
20        if !self.encoded_split.is_empty() {
21            #[allow(clippy::needless_borrow)]
22            #[allow(clippy::needless_borrows_for_generic_args)]
23            struct_ser.serialize_field("encodedSplit", pbjson::private::base64::encode(&self.encoded_split).as_str())?;
24        }
25        struct_ser.end()
26    }
27}
28impl<'de> serde::Deserialize<'de> for ConnectorSplit {
29    #[allow(deprecated)]
30    fn deserialize<D>(deserializer: D) -> std::result::Result<Self, D::Error>
31    where
32        D: serde::Deserializer<'de>,
33    {
34        const FIELDS: &[&str] = &[
35            "split_type",
36            "splitType",
37            "encoded_split",
38            "encodedSplit",
39        ];
40
41        #[allow(clippy::enum_variant_names)]
42        enum GeneratedField {
43            SplitType,
44            EncodedSplit,
45        }
46        impl<'de> serde::Deserialize<'de> for GeneratedField {
47            fn deserialize<D>(deserializer: D) -> std::result::Result<GeneratedField, D::Error>
48            where
49                D: serde::Deserializer<'de>,
50            {
51                struct GeneratedVisitor;
52
53                impl<'de> serde::de::Visitor<'de> for GeneratedVisitor {
54                    type Value = GeneratedField;
55
56                    fn expecting(&self, formatter: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
57                        write!(formatter, "expected one of: {:?}", &FIELDS)
58                    }
59
60                    #[allow(unused_variables)]
61                    fn visit_str<E>(self, value: &str) -> std::result::Result<GeneratedField, E>
62                    where
63                        E: serde::de::Error,
64                    {
65                        match value {
66                            "splitType" | "split_type" => Ok(GeneratedField::SplitType),
67                            "encodedSplit" | "encoded_split" => Ok(GeneratedField::EncodedSplit),
68                            _ => Err(serde::de::Error::unknown_field(value, FIELDS)),
69                        }
70                    }
71                }
72                deserializer.deserialize_identifier(GeneratedVisitor)
73            }
74        }
75        struct GeneratedVisitor;
76        impl<'de> serde::de::Visitor<'de> for GeneratedVisitor {
77            type Value = ConnectorSplit;
78
79            fn expecting(&self, formatter: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
80                formatter.write_str("struct source.ConnectorSplit")
81            }
82
83            fn visit_map<V>(self, mut map_: V) -> std::result::Result<ConnectorSplit, V::Error>
84                where
85                    V: serde::de::MapAccess<'de>,
86            {
87                let mut split_type__ = None;
88                let mut encoded_split__ = None;
89                while let Some(k) = map_.next_key()? {
90                    match k {
91                        GeneratedField::SplitType => {
92                            if split_type__.is_some() {
93                                return Err(serde::de::Error::duplicate_field("splitType"));
94                            }
95                            split_type__ = Some(map_.next_value()?);
96                        }
97                        GeneratedField::EncodedSplit => {
98                            if encoded_split__.is_some() {
99                                return Err(serde::de::Error::duplicate_field("encodedSplit"));
100                            }
101                            encoded_split__ = 
102                                Some(map_.next_value::<::pbjson::private::BytesDeserialize<_>>()?.0)
103                            ;
104                        }
105                    }
106                }
107                Ok(ConnectorSplit {
108                    split_type: split_type__.unwrap_or_default(),
109                    encoded_split: encoded_split__.unwrap_or_default(),
110                })
111            }
112        }
113        deserializer.deserialize_struct("source.ConnectorSplit", FIELDS, GeneratedVisitor)
114    }
115}
116impl serde::Serialize for ConnectorSplits {
117    #[allow(deprecated)]
118    fn serialize<S>(&self, serializer: S) -> std::result::Result<S::Ok, S::Error>
119    where
120        S: serde::Serializer,
121    {
122        use serde::ser::SerializeStruct;
123        let mut len = 0;
124        if !self.splits.is_empty() {
125            len += 1;
126        }
127        let mut struct_ser = serializer.serialize_struct("source.ConnectorSplits", len)?;
128        if !self.splits.is_empty() {
129            struct_ser.serialize_field("splits", &self.splits)?;
130        }
131        struct_ser.end()
132    }
133}
134impl<'de> serde::Deserialize<'de> for ConnectorSplits {
135    #[allow(deprecated)]
136    fn deserialize<D>(deserializer: D) -> std::result::Result<Self, D::Error>
137    where
138        D: serde::Deserializer<'de>,
139    {
140        const FIELDS: &[&str] = &[
141            "splits",
142        ];
143
144        #[allow(clippy::enum_variant_names)]
145        enum GeneratedField {
146            Splits,
147        }
148        impl<'de> serde::Deserialize<'de> for GeneratedField {
149            fn deserialize<D>(deserializer: D) -> std::result::Result<GeneratedField, D::Error>
150            where
151                D: serde::Deserializer<'de>,
152            {
153                struct GeneratedVisitor;
154
155                impl<'de> serde::de::Visitor<'de> for GeneratedVisitor {
156                    type Value = GeneratedField;
157
158                    fn expecting(&self, formatter: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
159                        write!(formatter, "expected one of: {:?}", &FIELDS)
160                    }
161
162                    #[allow(unused_variables)]
163                    fn visit_str<E>(self, value: &str) -> std::result::Result<GeneratedField, E>
164                    where
165                        E: serde::de::Error,
166                    {
167                        match value {
168                            "splits" => Ok(GeneratedField::Splits),
169                            _ => Err(serde::de::Error::unknown_field(value, FIELDS)),
170                        }
171                    }
172                }
173                deserializer.deserialize_identifier(GeneratedVisitor)
174            }
175        }
176        struct GeneratedVisitor;
177        impl<'de> serde::de::Visitor<'de> for GeneratedVisitor {
178            type Value = ConnectorSplits;
179
180            fn expecting(&self, formatter: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
181                formatter.write_str("struct source.ConnectorSplits")
182            }
183
184            fn visit_map<V>(self, mut map_: V) -> std::result::Result<ConnectorSplits, V::Error>
185                where
186                    V: serde::de::MapAccess<'de>,
187            {
188                let mut splits__ = None;
189                while let Some(k) = map_.next_key()? {
190                    match k {
191                        GeneratedField::Splits => {
192                            if splits__.is_some() {
193                                return Err(serde::de::Error::duplicate_field("splits"));
194                            }
195                            splits__ = Some(map_.next_value()?);
196                        }
197                    }
198                }
199                Ok(ConnectorSplits {
200                    splits: splits__.unwrap_or_default(),
201                })
202            }
203        }
204        deserializer.deserialize_struct("source.ConnectorSplits", FIELDS, GeneratedVisitor)
205    }
206}
207impl serde::Serialize for SourceActorInfo {
208    #[allow(deprecated)]
209    fn serialize<S>(&self, serializer: S) -> std::result::Result<S::Ok, S::Error>
210    where
211        S: serde::Serializer,
212    {
213        use serde::ser::SerializeStruct;
214        let mut len = 0;
215        if self.actor_id != 0 {
216            len += 1;
217        }
218        if self.splits.is_some() {
219            len += 1;
220        }
221        let mut struct_ser = serializer.serialize_struct("source.SourceActorInfo", len)?;
222        if self.actor_id != 0 {
223            struct_ser.serialize_field("actorId", &self.actor_id)?;
224        }
225        if let Some(v) = self.splits.as_ref() {
226            struct_ser.serialize_field("splits", v)?;
227        }
228        struct_ser.end()
229    }
230}
231impl<'de> serde::Deserialize<'de> for SourceActorInfo {
232    #[allow(deprecated)]
233    fn deserialize<D>(deserializer: D) -> std::result::Result<Self, D::Error>
234    where
235        D: serde::Deserializer<'de>,
236    {
237        const FIELDS: &[&str] = &[
238            "actor_id",
239            "actorId",
240            "splits",
241        ];
242
243        #[allow(clippy::enum_variant_names)]
244        enum GeneratedField {
245            ActorId,
246            Splits,
247        }
248        impl<'de> serde::Deserialize<'de> for GeneratedField {
249            fn deserialize<D>(deserializer: D) -> std::result::Result<GeneratedField, D::Error>
250            where
251                D: serde::Deserializer<'de>,
252            {
253                struct GeneratedVisitor;
254
255                impl<'de> serde::de::Visitor<'de> for GeneratedVisitor {
256                    type Value = GeneratedField;
257
258                    fn expecting(&self, formatter: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
259                        write!(formatter, "expected one of: {:?}", &FIELDS)
260                    }
261
262                    #[allow(unused_variables)]
263                    fn visit_str<E>(self, value: &str) -> std::result::Result<GeneratedField, E>
264                    where
265                        E: serde::de::Error,
266                    {
267                        match value {
268                            "actorId" | "actor_id" => Ok(GeneratedField::ActorId),
269                            "splits" => Ok(GeneratedField::Splits),
270                            _ => Err(serde::de::Error::unknown_field(value, FIELDS)),
271                        }
272                    }
273                }
274                deserializer.deserialize_identifier(GeneratedVisitor)
275            }
276        }
277        struct GeneratedVisitor;
278        impl<'de> serde::de::Visitor<'de> for GeneratedVisitor {
279            type Value = SourceActorInfo;
280
281            fn expecting(&self, formatter: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
282                formatter.write_str("struct source.SourceActorInfo")
283            }
284
285            fn visit_map<V>(self, mut map_: V) -> std::result::Result<SourceActorInfo, V::Error>
286                where
287                    V: serde::de::MapAccess<'de>,
288            {
289                let mut actor_id__ = None;
290                let mut splits__ = None;
291                while let Some(k) = map_.next_key()? {
292                    match k {
293                        GeneratedField::ActorId => {
294                            if actor_id__.is_some() {
295                                return Err(serde::de::Error::duplicate_field("actorId"));
296                            }
297                            actor_id__ = 
298                                Some(map_.next_value::<::pbjson::private::NumberDeserialize<_>>()?.0)
299                            ;
300                        }
301                        GeneratedField::Splits => {
302                            if splits__.is_some() {
303                                return Err(serde::de::Error::duplicate_field("splits"));
304                            }
305                            splits__ = map_.next_value()?;
306                        }
307                    }
308                }
309                Ok(SourceActorInfo {
310                    actor_id: actor_id__.unwrap_or_default(),
311                    splits: splits__,
312                })
313            }
314        }
315        deserializer.deserialize_struct("source.SourceActorInfo", FIELDS, GeneratedVisitor)
316    }
317}