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