crabka_protocol/opt/rustwide/workdir/generated/
ListConfigResourcesResponse.owned.rs1use bytes::{Buf, BufMut};
4
5use crate::primitives::fixed::{get_i8, get_i16, get_i32, put_i8, put_i16, put_i32};
6use crate::primitives::string_bytes::{
7 compact_string_len, get_compact_string_owned, get_string_owned, put_compact_string, put_string,
8 string_len,
9};
10use crate::tagged_fields::{WriteTaggedFields, read_tagged_fields, tagged_fields_len};
11use crate::{Decode, Encode, ProtocolError, UnknownTaggedFields};
12
13pub const API_KEY: i16 = 74;
14pub const MIN_VERSION: i16 = 0;
15pub const MAX_VERSION: i16 = 1;
16pub const FLEXIBLE_MIN: i16 = 0;
17
18#[inline]
19fn is_flexible(version: i16) -> bool {
20 version >= FLEXIBLE_MIN
21}
22
23#[derive(Debug, Clone, PartialEq, Eq, Default)]
24pub struct ListConfigResourcesResponse {
25 pub throttle_time_ms: i32,
26 pub error_code: i16,
27 pub config_resources: Vec<ConfigResource>,
28 pub unknown_tagged_fields: UnknownTaggedFields,
29}
30impl Encode for ListConfigResourcesResponse {
31 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
32 if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
33 return Err(ProtocolError::UnsupportedVersion {
34 api_key: API_KEY,
35 version,
36 });
37 }
38 let flex = is_flexible(version);
39 if version >= 0 {
40 put_i32(buf, self.throttle_time_ms);
41 }
42 if version >= 0 {
43 put_i16(buf, self.error_code);
44 }
45 if version >= 0 {
46 {
47 crate::primitives::array::put_array_len(buf, (self.config_resources).len(), flex);
48 for it in &self.config_resources {
49 it.encode(buf, version)?;
50 }
51 }
52 }
53 if flex {
54 let tagged = WriteTaggedFields::new();
55 tagged.write(buf, &self.unknown_tagged_fields);
56 }
57 Ok(())
58 }
59 fn encoded_len(&self, version: i16) -> usize {
60 let flex = is_flexible(version);
61 let mut n: usize = 0;
62 if version >= 0 {
63 n += 4;
64 }
65 if version >= 0 {
66 n += 2;
67 }
68 if version >= 0 {
69 n += {
70 let prefix = crate::primitives::array::array_len_prefix_len(
71 (self.config_resources).len(),
72 flex,
73 );
74 let body: usize = (self.config_resources)
75 .iter()
76 .map(|it| it.encoded_len(version))
77 .sum();
78 prefix + body
79 };
80 }
81 if flex {
82 let known_pairs: Vec<(u32, usize)> = Vec::new();
83 n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
84 }
85 n
86 }
87}
88impl Decode<'_> for ListConfigResourcesResponse {
89 fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
90 if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
91 return Err(ProtocolError::UnsupportedVersion {
92 api_key: API_KEY,
93 version,
94 });
95 }
96 let flex = is_flexible(version);
97 let mut out = Self::default();
98 if version >= 0 {
99 out.throttle_time_ms = get_i32(buf)?;
100 }
101 if version >= 0 {
102 out.error_code = get_i16(buf)?;
103 }
104 if version >= 0 {
105 out.config_resources = {
106 let n = crate::primitives::array::get_array_len(buf, flex)?;
107 let mut v = Vec::with_capacity(n);
108 for _ in 0..n {
109 v.push(ConfigResource::decode(buf, version)?);
110 }
111 v
112 };
113 }
114 if flex {
115 out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
116 }
117 Ok(out)
118 }
119}
120#[cfg(test)]
121impl ListConfigResourcesResponse {
122 #[must_use]
123 pub fn populated(version: i16) -> Self {
124 let mut m = Self::default();
125 if version >= 0 {
126 m.throttle_time_ms = 1i32;
127 }
128 if version >= 0 {
129 m.error_code = 1i16;
130 }
131 if version >= 0 {
132 m.config_resources = vec![ConfigResource::populated(version)];
133 }
134 m
135 }
136}
137#[derive(Debug, Clone, PartialEq, Eq)]
138pub struct ConfigResource {
139 pub resource_name: String,
140 pub resource_type: i8,
141 pub unknown_tagged_fields: UnknownTaggedFields,
142}
143impl Default for ConfigResource {
144 fn default() -> Self {
145 Self {
146 resource_name: String::new(),
147 resource_type: 16i8,
148 unknown_tagged_fields: Default::default(),
149 }
150 }
151}
152impl Encode for ConfigResource {
153 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
154 let flex = version >= 0;
155 if version >= 0 {
156 if flex {
157 put_compact_string(buf, &self.resource_name);
158 } else {
159 put_string(buf, &self.resource_name);
160 }
161 }
162 if version >= 1 {
163 put_i8(buf, self.resource_type);
164 }
165 if flex {
166 let tagged = WriteTaggedFields::new();
167 tagged.write(buf, &self.unknown_tagged_fields);
168 }
169 Ok(())
170 }
171 fn encoded_len(&self, version: i16) -> usize {
172 let flex = version >= 0;
173 let mut n: usize = 0;
174 if version >= 0 {
175 n += if flex {
176 compact_string_len(&self.resource_name)
177 } else {
178 string_len(&self.resource_name)
179 };
180 }
181 if version >= 1 {
182 n += 1;
183 }
184 if flex {
185 let known_pairs: Vec<(u32, usize)> = Vec::new();
186 n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
187 }
188 n
189 }
190}
191impl Decode<'_> for ConfigResource {
192 fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
193 let flex = version >= 0;
194 let mut out = Self::default();
195 if version >= 0 {
196 out.resource_name = if flex {
197 get_compact_string_owned(buf)?
198 } else {
199 get_string_owned(buf)?
200 };
201 }
202 if version >= 1 {
203 out.resource_type = get_i8(buf)?;
204 }
205 if flex {
206 out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
207 }
208 Ok(out)
209 }
210}
211#[cfg(test)]
212impl ConfigResource {
213 #[must_use]
214 pub fn populated(version: i16) -> Self {
215 let mut m = Self::default();
216 if version >= 0 {
217 m.resource_name = "x".to_string();
218 }
219 if version >= 1 {
220 m.resource_type = 1i8;
221 }
222 m
223 }
224}
225
226#[must_use]
229#[allow(unused_comparisons)]
230pub fn default_json(version: i16) -> ::serde_json::Value {
231 let mut obj = ::serde_json::Map::new();
232 obj.insert("throttleTimeMs".to_string(), ::serde_json::json!(0));
233 obj.insert("errorCode".to_string(), ::serde_json::json!(0));
234 obj.insert(
235 "configResources".to_string(),
236 ::serde_json::Value::Array(vec![]),
237 );
238 ::serde_json::Value::Object(obj)
239}