krabka_protocol/opt/rustwide/workdir/generated/
OffsetCommitResponse.owned.rs1use bytes::{Buf, BufMut};
4
5use crate::{
6 Decode, Encode, ProtocolError, UnknownTaggedFields,
7 primitives::{
8 fixed::{get_i16, get_i32, put_i16, put_i32},
9 string_bytes::{
10 compact_string_len, get_compact_string_owned, get_string_owned, put_compact_string,
11 put_string, string_len,
12 },
13 },
14 tagged_fields::{WriteTaggedFields, read_tagged_fields, tagged_fields_len},
15};
16pub const API_KEY: i16 = 8;
17pub const MIN_VERSION: i16 = 2;
18pub const MAX_VERSION: i16 = 10;
19pub const FLEXIBLE_MIN: i16 = 8;
20#[inline]
21#[must_use]
22pub fn is_flexible(version: i16) -> bool {
23 version >= FLEXIBLE_MIN
24}
25#[derive(Debug, Clone, PartialEq, Eq, Default)]
26pub struct OffsetCommitResponse {
27 pub throttle_time_ms: i32,
28 pub topics: Vec<OffsetCommitResponseTopic>,
29 pub unknown_tagged_fields: UnknownTaggedFields,
30}
31impl Encode for OffsetCommitResponse {
32 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
33 if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
34 return Err(ProtocolError::UnsupportedVersion {
35 api_key: API_KEY,
36 version,
37 });
38 }
39 let flex = is_flexible(version);
40 if version >= 3 {
41 put_i32(buf, self.throttle_time_ms);
42 }
43 if version >= 0 {
44 {
45 crate::primitives::array::put_array_len(buf, (self.topics).len(), flex);
46 for it in &self.topics {
47 it.encode(buf, version)?;
48 }
49 };
50 }
51 if flex {
52 let tagged = WriteTaggedFields::new();
53 tagged.write(buf, &self.unknown_tagged_fields);
54 }
55 Ok(())
56 }
57 fn encoded_len(&self, version: i16) -> usize {
58 let flex = is_flexible(version);
59 let mut n: usize = 0;
60 if version >= 3 {
61 n += 4;
62 }
63 if version >= 0 {
64 n += {
65 let prefix =
66 crate::primitives::array::array_len_prefix_len((self.topics).len(), flex);
67 let body: usize = (self.topics).iter().map(|it| it.encoded_len(version)).sum();
68 prefix + body
69 };
70 }
71 if flex {
72 let known_pairs: Vec<(u32, usize)> = Vec::new();
73 n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
74 }
75 n
76 }
77}
78impl Decode<'_> for OffsetCommitResponse {
79 fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
80 if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
81 return Err(ProtocolError::UnsupportedVersion {
82 api_key: API_KEY,
83 version,
84 });
85 }
86 let flex = is_flexible(version);
87 let mut out = Self::default();
88 if version >= 3 {
89 out.throttle_time_ms = get_i32(buf)?;
90 }
91 if version >= 0 {
92 out.topics = {
93 let n = crate::primitives::array::get_array_len(buf, flex)?;
94 let mut v = Vec::with_capacity(n);
95 for _ in 0..n {
96 v.push(OffsetCommitResponseTopic::decode(buf, version)?);
97 }
98 v
99 };
100 }
101 if flex {
102 out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
103 }
104 Ok(out)
105 }
106}
107#[cfg(test)]
108impl OffsetCommitResponse {
109 #[must_use]
110 pub fn populated(version: i16) -> Self {
111 let mut m = Self::default();
112 if version >= 3 {
113 m.throttle_time_ms = 1i32;
114 }
115 if version >= 0 {
116 m.topics = vec![OffsetCommitResponseTopic::populated(version)];
117 }
118 m
119 }
120}
121#[derive(Debug, Clone, PartialEq, Eq, Default)]
122pub struct OffsetCommitResponseTopic {
123 pub name: String,
124 pub topic_id: crate::primitives::uuid::Uuid,
125 pub partitions: Vec<OffsetCommitResponsePartition>,
126 pub unknown_tagged_fields: UnknownTaggedFields,
127}
128impl Encode for OffsetCommitResponseTopic {
129 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
130 let flex = version >= 8;
131 if (0..=9).contains(&version) {
132 if flex {
133 let () = put_compact_string(buf, &self.name);
134 } else {
135 let () = put_string(buf, &self.name);
136 }
137 }
138 if version >= 10 {
139 crate::primitives::uuid::put_uuid(buf, self.topic_id);
140 }
141 if version >= 0 {
142 {
143 crate::primitives::array::put_array_len(buf, (self.partitions).len(), flex);
144 for it in &self.partitions {
145 it.encode(buf, version)?;
146 }
147 };
148 }
149 if flex {
150 let tagged = WriteTaggedFields::new();
151 tagged.write(buf, &self.unknown_tagged_fields);
152 }
153 Ok(())
154 }
155 fn encoded_len(&self, version: i16) -> usize {
156 let flex = version >= 8;
157 let mut n: usize = 0;
158 if (0..=9).contains(&version) {
159 n += if flex {
160 compact_string_len(&self.name)
161 } else {
162 string_len(&self.name)
163 };
164 }
165 if version >= 10 {
166 n += 16;
167 }
168 if version >= 0 {
169 n += {
170 let prefix =
171 crate::primitives::array::array_len_prefix_len((self.partitions).len(), flex);
172 let body: usize = (self.partitions)
173 .iter()
174 .map(|it| it.encoded_len(version))
175 .sum();
176 prefix + body
177 };
178 }
179 if flex {
180 let known_pairs: Vec<(u32, usize)> = Vec::new();
181 n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
182 }
183 n
184 }
185}
186impl Decode<'_> for OffsetCommitResponseTopic {
187 fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
188 let flex = version >= 8;
189 let mut out = Self::default();
190 if (0..=9).contains(&version) {
191 out.name = if flex {
192 get_compact_string_owned(buf)?
193 } else {
194 get_string_owned(buf)?
195 };
196 }
197 if version >= 10 {
198 out.topic_id = crate::primitives::uuid::get_uuid(buf)?;
199 }
200 if version >= 0 {
201 out.partitions = {
202 let n = crate::primitives::array::get_array_len(buf, flex)?;
203 let mut v = Vec::with_capacity(n);
204 for _ in 0..n {
205 v.push(OffsetCommitResponsePartition::decode(buf, version)?);
206 }
207 v
208 };
209 }
210 if flex {
211 out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
212 }
213 Ok(out)
214 }
215}
216#[cfg(test)]
217impl OffsetCommitResponseTopic {
218 #[must_use]
219 pub fn populated(version: i16) -> Self {
220 let mut m = Self::default();
221 if (0..=9).contains(&version) {
222 m.name = "x".to_string();
223 }
224 if version >= 10 {
225 m.topic_id = crate::primitives::uuid::Uuid([1u8; 16]);
226 }
227 if version >= 0 {
228 m.partitions = vec![OffsetCommitResponsePartition::populated(version)];
229 }
230 m
231 }
232}
233#[derive(Debug, Clone, PartialEq, Eq, Default)]
234pub struct OffsetCommitResponsePartition {
235 pub partition_index: i32,
236 pub error_code: i16,
237 pub unknown_tagged_fields: UnknownTaggedFields,
238}
239impl Encode for OffsetCommitResponsePartition {
240 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
241 let flex = version >= 8;
242 if version >= 0 {
243 put_i32(buf, self.partition_index);
244 }
245 if version >= 0 {
246 put_i16(buf, self.error_code);
247 }
248 if flex {
249 let tagged = WriteTaggedFields::new();
250 tagged.write(buf, &self.unknown_tagged_fields);
251 }
252 Ok(())
253 }
254 fn encoded_len(&self, version: i16) -> usize {
255 let flex = version >= 8;
256 let mut n: usize = 0;
257 if version >= 0 {
258 n += 4;
259 }
260 if version >= 0 {
261 n += 2;
262 }
263 if flex {
264 let known_pairs: Vec<(u32, usize)> = Vec::new();
265 n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
266 }
267 n
268 }
269}
270impl Decode<'_> for OffsetCommitResponsePartition {
271 fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
272 let flex = version >= 8;
273 let mut out = Self::default();
274 if version >= 0 {
275 out.partition_index = get_i32(buf)?;
276 }
277 if version >= 0 {
278 out.error_code = get_i16(buf)?;
279 }
280 if flex {
281 out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
282 }
283 Ok(out)
284 }
285}
286#[cfg(test)]
287impl OffsetCommitResponsePartition {
288 #[must_use]
289 pub fn populated(version: i16) -> Self {
290 let mut m = Self::default();
291 if version >= 0 {
292 m.partition_index = 1i32;
293 }
294 if version >= 0 {
295 m.error_code = 1i16;
296 }
297 m
298 }
299}
300#[must_use]
303#[allow(unused_comparisons)]
304pub fn default_json(version: i16) -> ::serde_json::Value {
305 let mut obj = ::serde_json::Map::new();
306 if version >= 3 {
307 obj.insert("throttleTimeMs".to_string(), ::serde_json::json!(0));
308 }
309 obj.insert("topics".to_string(), ::serde_json::Value::Array(vec![]));
310 ::serde_json::Value::Object(obj)
311}