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