1use crate::java_binding::*;
2impl serde::Serialize for KeyRange {
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.left.is_empty() {
11 len += 1;
12 }
13 if !self.right.is_empty() {
14 len += 1;
15 }
16 if self.left_bound != 0 {
17 len += 1;
18 }
19 if self.right_bound != 0 {
20 len += 1;
21 }
22 let mut struct_ser = serializer.serialize_struct("java_binding.KeyRange", len)?;
23 if !self.left.is_empty() {
24 #[allow(clippy::needless_borrow)]
25 #[allow(clippy::needless_borrows_for_generic_args)]
26 struct_ser.serialize_field("left", pbjson::private::base64::encode(&self.left).as_str())?;
27 }
28 if !self.right.is_empty() {
29 #[allow(clippy::needless_borrow)]
30 #[allow(clippy::needless_borrows_for_generic_args)]
31 struct_ser.serialize_field("right", pbjson::private::base64::encode(&self.right).as_str())?;
32 }
33 if self.left_bound != 0 {
34 let v = key_range::Bound::try_from(self.left_bound)
35 .map_err(|_| serde::ser::Error::custom(format!("Invalid variant {}", self.left_bound)))?;
36 struct_ser.serialize_field("leftBound", &v)?;
37 }
38 if self.right_bound != 0 {
39 let v = key_range::Bound::try_from(self.right_bound)
40 .map_err(|_| serde::ser::Error::custom(format!("Invalid variant {}", self.right_bound)))?;
41 struct_ser.serialize_field("rightBound", &v)?;
42 }
43 struct_ser.end()
44 }
45}
46impl<'de> serde::Deserialize<'de> for KeyRange {
47 #[allow(deprecated)]
48 fn deserialize<D>(deserializer: D) -> std::result::Result<Self, D::Error>
49 where
50 D: serde::Deserializer<'de>,
51 {
52 const FIELDS: &[&str] = &[
53 "left",
54 "right",
55 "left_bound",
56 "leftBound",
57 "right_bound",
58 "rightBound",
59 ];
60
61 #[allow(clippy::enum_variant_names)]
62 enum GeneratedField {
63 Left,
64 Right,
65 LeftBound,
66 RightBound,
67 }
68 impl<'de> serde::Deserialize<'de> for GeneratedField {
69 fn deserialize<D>(deserializer: D) -> std::result::Result<GeneratedField, D::Error>
70 where
71 D: serde::Deserializer<'de>,
72 {
73 struct GeneratedVisitor;
74
75 impl<'de> serde::de::Visitor<'de> for GeneratedVisitor {
76 type Value = GeneratedField;
77
78 fn expecting(&self, formatter: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
79 write!(formatter, "expected one of: {:?}", &FIELDS)
80 }
81
82 #[allow(unused_variables)]
83 fn visit_str<E>(self, value: &str) -> std::result::Result<GeneratedField, E>
84 where
85 E: serde::de::Error,
86 {
87 match value {
88 "left" => Ok(GeneratedField::Left),
89 "right" => Ok(GeneratedField::Right),
90 "leftBound" | "left_bound" => Ok(GeneratedField::LeftBound),
91 "rightBound" | "right_bound" => Ok(GeneratedField::RightBound),
92 _ => Err(serde::de::Error::unknown_field(value, FIELDS)),
93 }
94 }
95 }
96 deserializer.deserialize_identifier(GeneratedVisitor)
97 }
98 }
99 struct GeneratedVisitor;
100 impl<'de> serde::de::Visitor<'de> for GeneratedVisitor {
101 type Value = KeyRange;
102
103 fn expecting(&self, formatter: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
104 formatter.write_str("struct java_binding.KeyRange")
105 }
106
107 fn visit_map<V>(self, mut map_: V) -> std::result::Result<KeyRange, V::Error>
108 where
109 V: serde::de::MapAccess<'de>,
110 {
111 let mut left__ = None;
112 let mut right__ = None;
113 let mut left_bound__ = None;
114 let mut right_bound__ = None;
115 while let Some(k) = map_.next_key()? {
116 match k {
117 GeneratedField::Left => {
118 if left__.is_some() {
119 return Err(serde::de::Error::duplicate_field("left"));
120 }
121 left__ =
122 Some(map_.next_value::<::pbjson::private::BytesDeserialize<_>>()?.0)
123 ;
124 }
125 GeneratedField::Right => {
126 if right__.is_some() {
127 return Err(serde::de::Error::duplicate_field("right"));
128 }
129 right__ =
130 Some(map_.next_value::<::pbjson::private::BytesDeserialize<_>>()?.0)
131 ;
132 }
133 GeneratedField::LeftBound => {
134 if left_bound__.is_some() {
135 return Err(serde::de::Error::duplicate_field("leftBound"));
136 }
137 left_bound__ = Some(map_.next_value::<key_range::Bound>()? as i32);
138 }
139 GeneratedField::RightBound => {
140 if right_bound__.is_some() {
141 return Err(serde::de::Error::duplicate_field("rightBound"));
142 }
143 right_bound__ = Some(map_.next_value::<key_range::Bound>()? as i32);
144 }
145 }
146 }
147 Ok(KeyRange {
148 left: left__.unwrap_or_default(),
149 right: right__.unwrap_or_default(),
150 left_bound: left_bound__.unwrap_or_default(),
151 right_bound: right_bound__.unwrap_or_default(),
152 })
153 }
154 }
155 deserializer.deserialize_struct("java_binding.KeyRange", FIELDS, GeneratedVisitor)
156 }
157}
158impl serde::Serialize for key_range::Bound {
159 #[allow(deprecated)]
160 fn serialize<S>(&self, serializer: S) -> std::result::Result<S::Ok, S::Error>
161 where
162 S: serde::Serializer,
163 {
164 let variant = match self {
165 Self::Unspecified => "UNSPECIFIED",
166 Self::Unbounded => "UNBOUNDED",
167 Self::Included => "INCLUDED",
168 Self::Excluded => "EXCLUDED",
169 };
170 serializer.serialize_str(variant)
171 }
172}
173impl<'de> serde::Deserialize<'de> for key_range::Bound {
174 #[allow(deprecated)]
175 fn deserialize<D>(deserializer: D) -> std::result::Result<Self, D::Error>
176 where
177 D: serde::Deserializer<'de>,
178 {
179 const FIELDS: &[&str] = &[
180 "UNSPECIFIED",
181 "UNBOUNDED",
182 "INCLUDED",
183 "EXCLUDED",
184 ];
185
186 struct GeneratedVisitor;
187
188 impl<'de> serde::de::Visitor<'de> for GeneratedVisitor {
189 type Value = key_range::Bound;
190
191 fn expecting(&self, formatter: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
192 write!(formatter, "expected one of: {:?}", &FIELDS)
193 }
194
195 fn visit_i64<E>(self, v: i64) -> std::result::Result<Self::Value, E>
196 where
197 E: serde::de::Error,
198 {
199 i32::try_from(v)
200 .ok()
201 .and_then(|x| x.try_into().ok())
202 .ok_or_else(|| {
203 serde::de::Error::invalid_value(serde::de::Unexpected::Signed(v), &self)
204 })
205 }
206
207 fn visit_u64<E>(self, v: u64) -> std::result::Result<Self::Value, E>
208 where
209 E: serde::de::Error,
210 {
211 i32::try_from(v)
212 .ok()
213 .and_then(|x| x.try_into().ok())
214 .ok_or_else(|| {
215 serde::de::Error::invalid_value(serde::de::Unexpected::Unsigned(v), &self)
216 })
217 }
218
219 fn visit_str<E>(self, value: &str) -> std::result::Result<Self::Value, E>
220 where
221 E: serde::de::Error,
222 {
223 match value {
224 "UNSPECIFIED" => Ok(key_range::Bound::Unspecified),
225 "UNBOUNDED" => Ok(key_range::Bound::Unbounded),
226 "INCLUDED" => Ok(key_range::Bound::Included),
227 "EXCLUDED" => Ok(key_range::Bound::Excluded),
228 _ => Err(serde::de::Error::unknown_variant(value, FIELDS)),
229 }
230 }
231 }
232 deserializer.deserialize_any(GeneratedVisitor)
233 }
234}
235impl serde::Serialize for ReadPlan {
236 #[allow(deprecated)]
237 fn serialize<S>(&self, serializer: S) -> std::result::Result<S::Ok, S::Error>
238 where
239 S: serde::Serializer,
240 {
241 use serde::ser::SerializeStruct;
242 let mut len = 0;
243 if !self.object_store_url.is_empty() {
244 len += 1;
245 }
246 if !self.data_dir.is_empty() {
247 len += 1;
248 }
249 if self.key_range.is_some() {
250 len += 1;
251 }
252 if self.table_id != 0 {
253 len += 1;
254 }
255 if self.epoch != 0 {
256 len += 1;
257 }
258 if self.version.is_some() {
259 len += 1;
260 }
261 if self.table_catalog.is_some() {
262 len += 1;
263 }
264 if !self.vnode_ids.is_empty() {
265 len += 1;
266 }
267 if self.use_new_object_prefix_strategy {
268 len += 1;
269 }
270 let mut struct_ser = serializer.serialize_struct("java_binding.ReadPlan", len)?;
271 if !self.object_store_url.is_empty() {
272 struct_ser.serialize_field("objectStoreUrl", &self.object_store_url)?;
273 }
274 if !self.data_dir.is_empty() {
275 struct_ser.serialize_field("dataDir", &self.data_dir)?;
276 }
277 if let Some(v) = self.key_range.as_ref() {
278 struct_ser.serialize_field("keyRange", v)?;
279 }
280 if self.table_id != 0 {
281 struct_ser.serialize_field("tableId", &self.table_id)?;
282 }
283 if self.epoch != 0 {
284 #[allow(clippy::needless_borrow)]
285 #[allow(clippy::needless_borrows_for_generic_args)]
286 struct_ser.serialize_field("epoch", ToString::to_string(&self.epoch).as_str())?;
287 }
288 if let Some(v) = self.version.as_ref() {
289 struct_ser.serialize_field("version", v)?;
290 }
291 if let Some(v) = self.table_catalog.as_ref() {
292 struct_ser.serialize_field("tableCatalog", v)?;
293 }
294 if !self.vnode_ids.is_empty() {
295 struct_ser.serialize_field("vnodeIds", &self.vnode_ids)?;
296 }
297 if self.use_new_object_prefix_strategy {
298 struct_ser.serialize_field("useNewObjectPrefixStrategy", &self.use_new_object_prefix_strategy)?;
299 }
300 struct_ser.end()
301 }
302}
303impl<'de> serde::Deserialize<'de> for ReadPlan {
304 #[allow(deprecated)]
305 fn deserialize<D>(deserializer: D) -> std::result::Result<Self, D::Error>
306 where
307 D: serde::Deserializer<'de>,
308 {
309 const FIELDS: &[&str] = &[
310 "object_store_url",
311 "objectStoreUrl",
312 "data_dir",
313 "dataDir",
314 "key_range",
315 "keyRange",
316 "table_id",
317 "tableId",
318 "epoch",
319 "version",
320 "table_catalog",
321 "tableCatalog",
322 "vnode_ids",
323 "vnodeIds",
324 "use_new_object_prefix_strategy",
325 "useNewObjectPrefixStrategy",
326 ];
327
328 #[allow(clippy::enum_variant_names)]
329 enum GeneratedField {
330 ObjectStoreUrl,
331 DataDir,
332 KeyRange,
333 TableId,
334 Epoch,
335 Version,
336 TableCatalog,
337 VnodeIds,
338 UseNewObjectPrefixStrategy,
339 }
340 impl<'de> serde::Deserialize<'de> for GeneratedField {
341 fn deserialize<D>(deserializer: D) -> std::result::Result<GeneratedField, D::Error>
342 where
343 D: serde::Deserializer<'de>,
344 {
345 struct GeneratedVisitor;
346
347 impl<'de> serde::de::Visitor<'de> for GeneratedVisitor {
348 type Value = GeneratedField;
349
350 fn expecting(&self, formatter: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
351 write!(formatter, "expected one of: {:?}", &FIELDS)
352 }
353
354 #[allow(unused_variables)]
355 fn visit_str<E>(self, value: &str) -> std::result::Result<GeneratedField, E>
356 where
357 E: serde::de::Error,
358 {
359 match value {
360 "objectStoreUrl" | "object_store_url" => Ok(GeneratedField::ObjectStoreUrl),
361 "dataDir" | "data_dir" => Ok(GeneratedField::DataDir),
362 "keyRange" | "key_range" => Ok(GeneratedField::KeyRange),
363 "tableId" | "table_id" => Ok(GeneratedField::TableId),
364 "epoch" => Ok(GeneratedField::Epoch),
365 "version" => Ok(GeneratedField::Version),
366 "tableCatalog" | "table_catalog" => Ok(GeneratedField::TableCatalog),
367 "vnodeIds" | "vnode_ids" => Ok(GeneratedField::VnodeIds),
368 "useNewObjectPrefixStrategy" | "use_new_object_prefix_strategy" => Ok(GeneratedField::UseNewObjectPrefixStrategy),
369 _ => Err(serde::de::Error::unknown_field(value, FIELDS)),
370 }
371 }
372 }
373 deserializer.deserialize_identifier(GeneratedVisitor)
374 }
375 }
376 struct GeneratedVisitor;
377 impl<'de> serde::de::Visitor<'de> for GeneratedVisitor {
378 type Value = ReadPlan;
379
380 fn expecting(&self, formatter: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
381 formatter.write_str("struct java_binding.ReadPlan")
382 }
383
384 fn visit_map<V>(self, mut map_: V) -> std::result::Result<ReadPlan, V::Error>
385 where
386 V: serde::de::MapAccess<'de>,
387 {
388 let mut object_store_url__ = None;
389 let mut data_dir__ = None;
390 let mut key_range__ = None;
391 let mut table_id__ = None;
392 let mut epoch__ = None;
393 let mut version__ = None;
394 let mut table_catalog__ = None;
395 let mut vnode_ids__ = None;
396 let mut use_new_object_prefix_strategy__ = None;
397 while let Some(k) = map_.next_key()? {
398 match k {
399 GeneratedField::ObjectStoreUrl => {
400 if object_store_url__.is_some() {
401 return Err(serde::de::Error::duplicate_field("objectStoreUrl"));
402 }
403 object_store_url__ = Some(map_.next_value()?);
404 }
405 GeneratedField::DataDir => {
406 if data_dir__.is_some() {
407 return Err(serde::de::Error::duplicate_field("dataDir"));
408 }
409 data_dir__ = Some(map_.next_value()?);
410 }
411 GeneratedField::KeyRange => {
412 if key_range__.is_some() {
413 return Err(serde::de::Error::duplicate_field("keyRange"));
414 }
415 key_range__ = map_.next_value()?;
416 }
417 GeneratedField::TableId => {
418 if table_id__.is_some() {
419 return Err(serde::de::Error::duplicate_field("tableId"));
420 }
421 table_id__ =
422 Some(map_.next_value::<::pbjson::private::NumberDeserialize<_>>()?.0)
423 ;
424 }
425 GeneratedField::Epoch => {
426 if epoch__.is_some() {
427 return Err(serde::de::Error::duplicate_field("epoch"));
428 }
429 epoch__ =
430 Some(map_.next_value::<::pbjson::private::NumberDeserialize<_>>()?.0)
431 ;
432 }
433 GeneratedField::Version => {
434 if version__.is_some() {
435 return Err(serde::de::Error::duplicate_field("version"));
436 }
437 version__ = map_.next_value()?;
438 }
439 GeneratedField::TableCatalog => {
440 if table_catalog__.is_some() {
441 return Err(serde::de::Error::duplicate_field("tableCatalog"));
442 }
443 table_catalog__ = map_.next_value()?;
444 }
445 GeneratedField::VnodeIds => {
446 if vnode_ids__.is_some() {
447 return Err(serde::de::Error::duplicate_field("vnodeIds"));
448 }
449 vnode_ids__ =
450 Some(map_.next_value::<Vec<::pbjson::private::NumberDeserialize<_>>>()?
451 .into_iter().map(|x| x.0).collect())
452 ;
453 }
454 GeneratedField::UseNewObjectPrefixStrategy => {
455 if use_new_object_prefix_strategy__.is_some() {
456 return Err(serde::de::Error::duplicate_field("useNewObjectPrefixStrategy"));
457 }
458 use_new_object_prefix_strategy__ = Some(map_.next_value()?);
459 }
460 }
461 }
462 Ok(ReadPlan {
463 object_store_url: object_store_url__.unwrap_or_default(),
464 data_dir: data_dir__.unwrap_or_default(),
465 key_range: key_range__,
466 table_id: table_id__.unwrap_or_default(),
467 epoch: epoch__.unwrap_or_default(),
468 version: version__,
469 table_catalog: table_catalog__,
470 vnode_ids: vnode_ids__.unwrap_or_default(),
471 use_new_object_prefix_strategy: use_new_object_prefix_strategy__.unwrap_or_default(),
472 })
473 }
474 }
475 deserializer.deserialize_struct("java_binding.ReadPlan", FIELDS, GeneratedVisitor)
476 }
477}