crabka_protocol/opt/rustwide/workdir/generated/
ListConfigResourcesRequest.owned.rs1use crate::primitives::fixed::{get_i8, put_i8};
4use crate::tagged_fields::{WriteTaggedFields, read_tagged_fields, tagged_fields_len};
5use crate::{Decode, Encode, ProtocolError, UnknownTaggedFields};
6use bytes::{Buf, BufMut};
7pub const API_KEY: i16 = 74;
8pub const MIN_VERSION: i16 = 0;
9pub const MAX_VERSION: i16 = 1;
10pub const FLEXIBLE_MIN: i16 = 0;
11#[inline]
12fn is_flexible(version: i16) -> bool {
13 version >= FLEXIBLE_MIN
14}
15#[derive(Debug, Clone, PartialEq, Eq, Default)]
16pub struct ListConfigResourcesRequest {
17 pub resource_types: Vec<i8>,
18 pub unknown_tagged_fields: UnknownTaggedFields,
19}
20impl Encode for ListConfigResourcesRequest {
21 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
22 if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
23 return Err(ProtocolError::UnsupportedVersion {
24 api_key: API_KEY,
25 version,
26 });
27 }
28 let flex = is_flexible(version);
29 if version >= 1 {
30 {
31 crate::primitives::array::put_array_len(buf, (self.resource_types).len(), flex);
32 for it in &self.resource_types {
33 put_i8(buf, *it);
34 }
35 }
36 }
37 if flex {
38 let tagged = WriteTaggedFields::new();
39 tagged.write(buf, &self.unknown_tagged_fields);
40 }
41 Ok(())
42 }
43 fn encoded_len(&self, version: i16) -> usize {
44 let flex = is_flexible(version);
45 let mut n: usize = 0;
46 if version >= 1 {
47 n += {
48 let prefix = crate::primitives::array::array_len_prefix_len(
49 (self.resource_types).len(),
50 flex,
51 );
52 let body: usize = (self.resource_types).iter().map(|_| 1).sum();
53 prefix + body
54 };
55 }
56 if flex {
57 let known_pairs: Vec<(u32, usize)> = Vec::new();
58 n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
59 }
60 n
61 }
62}
63impl Decode<'_> for ListConfigResourcesRequest {
64 fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
65 if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
66 return Err(ProtocolError::UnsupportedVersion {
67 api_key: API_KEY,
68 version,
69 });
70 }
71 let flex = is_flexible(version);
72 let mut out = Self::default();
73 if version >= 1 {
74 out.resource_types = {
75 let n = crate::primitives::array::get_array_len(buf, flex)?;
76 let mut v = Vec::with_capacity(n);
77 for _ in 0..n {
78 v.push(get_i8(buf)?);
79 }
80 v
81 };
82 }
83 if flex {
84 out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
85 }
86 Ok(out)
87 }
88}
89#[cfg(test)]
90impl ListConfigResourcesRequest {
91 #[must_use]
92 pub fn populated(version: i16) -> Self {
93 let mut m = Self::default();
94 if version >= 1 {
95 m.resource_types = vec![1i8];
96 }
97 m
98 }
99}
100#[must_use]
103#[allow(unused_comparisons)]
104pub fn default_json(version: i16) -> ::serde_json::Value {
105 let mut obj = ::serde_json::Map::new();
106 if version >= 1 {
107 obj.insert(
108 "resourceTypes".to_string(),
109 ::serde_json::Value::Array(vec![]),
110 );
111 }
112 ::serde_json::Value::Object(obj)
113}
114impl crate::ProtocolRequest for ListConfigResourcesRequest {
115 const API_KEY: i16 = API_KEY;
116 const MIN_VERSION: i16 = MIN_VERSION;
117 const MAX_VERSION: i16 = MAX_VERSION;
118 const FLEXIBLE_MIN: i16 = FLEXIBLE_MIN;
119 type Response = super::list_config_resources_response::ListConfigResourcesResponse;
120}