krabka_protocol/opt/rustwide/workdir/generated/
GetReplicaLogInfoResponse.borrowed.rs1use bytes::BufMut;
3
4use crate::{
5 DecodeBorrow, Encode, ProtocolError, UnknownTaggedFields,
6 primitives::{
7 fixed::{get_i16, get_i32, get_i64, put_i16, put_i32, put_i64},
8 string_bytes::{
9 compact_nullable_string_len, nullable_string_len, put_compact_nullable_string,
10 put_nullable_string,
11 },
12 string_bytes_borrowed::{
13 get_compact_nullable_string_borrowed, get_nullable_string_borrowed,
14 },
15 },
16 tagged_fields::{WriteTaggedFields, read_tagged_fields, tagged_fields_len},
17};
18pub const API_KEY: i16 = 1020;
19pub const MIN_VERSION: i16 = 0;
20pub const MAX_VERSION: i16 = 0;
21pub const FLEXIBLE_MIN: i16 = 0;
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 GetReplicaLogInfoResponse<'a> {
29 pub broker_epoch: i64,
30 pub topic_partition_log_info_list: Vec<TopicPartitionLogInfo<'a>>,
31 pub unknown_tagged_fields: UnknownTaggedFields,
32}
33impl GetReplicaLogInfoResponse<'_> {
34 #[must_use]
38 pub fn to_owned(
39 &self,
40 ) -> crate::owned::get_replica_log_info_response::GetReplicaLogInfoResponse {
41 crate::owned::get_replica_log_info_response::GetReplicaLogInfoResponse {
42 broker_epoch: (self.broker_epoch),
43 topic_partition_log_info_list: (self.topic_partition_log_info_list)
44 .iter()
45 .map(TopicPartitionLogInfo::to_owned)
46 .collect(),
47 unknown_tagged_fields: self.unknown_tagged_fields.clone(),
48 }
49 }
50}
51impl Encode for GetReplicaLogInfoResponse<'_> {
52 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
53 if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
54 return Err(ProtocolError::UnsupportedVersion {
55 api_key: API_KEY,
56 version,
57 });
58 }
59 let flex = is_flexible(version);
60 if version >= 0 {
61 put_i64(buf, self.broker_epoch);
62 }
63 if version >= 0 {
64 {
65 crate::primitives::array::put_array_len(
66 buf,
67 (self.topic_partition_log_info_list).len(),
68 flex,
69 );
70 for it in &self.topic_partition_log_info_list {
71 it.encode(buf, version)?;
72 }
73 };
74 }
75 if flex {
76 let tagged = WriteTaggedFields::new();
77 tagged.write(buf, &self.unknown_tagged_fields);
78 }
79 Ok(())
80 }
81 fn encoded_len(&self, version: i16) -> usize {
82 let flex = is_flexible(version);
83 let mut n: usize = 0;
84 if version >= 0 {
85 n += 8;
86 }
87 if version >= 0 {
88 n += {
89 let prefix = crate::primitives::array::array_len_prefix_len(
90 (self.topic_partition_log_info_list).len(),
91 flex,
92 );
93 let body: usize = (self.topic_partition_log_info_list)
94 .iter()
95 .map(|it| it.encoded_len(version))
96 .sum();
97 prefix + body
98 };
99 }
100 if flex {
101 let known_pairs: Vec<(u32, usize)> = Vec::new();
102 n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
103 }
104 n
105 }
106}
107impl<'de> DecodeBorrow<'de> for GetReplicaLogInfoResponse<'de> {
108 fn decode_borrow(buf: &mut &'de [u8], version: i16) -> Result<Self, ProtocolError> {
109 if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
110 return Err(ProtocolError::UnsupportedVersion {
111 api_key: API_KEY,
112 version,
113 });
114 }
115 let flex = is_flexible(version);
116 let mut out = Self::default();
117 if version >= 0 {
118 out.broker_epoch = get_i64(buf)?;
119 }
120 if version >= 0 {
121 out.topic_partition_log_info_list = {
122 let n = crate::primitives::array::get_array_len(buf, flex)?;
123 let mut v = Vec::with_capacity(n);
124 for _ in 0..n {
125 v.push(TopicPartitionLogInfo::decode_borrow(buf, version)?);
126 }
127 v
128 };
129 }
130 if flex {
131 out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
132 }
133 Ok(out)
134 }
135}
136#[cfg(test)]
137impl GetReplicaLogInfoResponse<'_> {
138 #[must_use]
139 pub fn populated(version: i16) -> Self {
140 let mut m = Self::default();
141 if version >= 0 {
142 m.broker_epoch = 1i64;
143 }
144 if version >= 0 {
145 m.topic_partition_log_info_list = vec![TopicPartitionLogInfo::populated(version)];
146 }
147 m
148 }
149}
150#[derive(Debug, Clone, PartialEq, Eq, Default)]
151pub struct TopicPartitionLogInfo<'a> {
152 pub topic_id: crate::primitives::uuid::Uuid,
153 pub partition_log_info: Vec<PartitionLogInfo<'a>>,
154 pub unknown_tagged_fields: UnknownTaggedFields,
155}
156impl TopicPartitionLogInfo<'_> {
157 #[must_use]
161 pub fn to_owned(&self) -> crate::owned::get_replica_log_info_response::TopicPartitionLogInfo {
162 crate::owned::get_replica_log_info_response::TopicPartitionLogInfo {
163 topic_id: (self.topic_id),
164 partition_log_info: (self.partition_log_info)
165 .iter()
166 .map(PartitionLogInfo::to_owned)
167 .collect(),
168 unknown_tagged_fields: self.unknown_tagged_fields.clone(),
169 }
170 }
171}
172impl Encode for TopicPartitionLogInfo<'_> {
173 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
174 let flex = version >= 0;
175 if version >= 0 {
176 crate::primitives::uuid::put_uuid(buf, self.topic_id);
177 }
178 if version >= 0 {
179 {
180 crate::primitives::array::put_array_len(buf, (self.partition_log_info).len(), flex);
181 for it in &self.partition_log_info {
182 it.encode(buf, version)?;
183 }
184 };
185 }
186 if flex {
187 let tagged = WriteTaggedFields::new();
188 tagged.write(buf, &self.unknown_tagged_fields);
189 }
190 Ok(())
191 }
192 fn encoded_len(&self, version: i16) -> usize {
193 let flex = version >= 0;
194 let mut n: usize = 0;
195 if version >= 0 {
196 n += 16;
197 }
198 if version >= 0 {
199 n += {
200 let prefix = crate::primitives::array::array_len_prefix_len(
201 (self.partition_log_info).len(),
202 flex,
203 );
204 let body: usize = (self.partition_log_info)
205 .iter()
206 .map(|it| it.encoded_len(version))
207 .sum();
208 prefix + body
209 };
210 }
211 if flex {
212 let known_pairs: Vec<(u32, usize)> = Vec::new();
213 n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
214 }
215 n
216 }
217}
218impl<'de> DecodeBorrow<'de> for TopicPartitionLogInfo<'de> {
219 fn decode_borrow(buf: &mut &'de [u8], version: i16) -> Result<Self, ProtocolError> {
220 let flex = version >= 0;
221 let mut out = Self::default();
222 if version >= 0 {
223 out.topic_id = crate::primitives::uuid::get_uuid(buf)?;
224 }
225 if version >= 0 {
226 out.partition_log_info = {
227 let n = crate::primitives::array::get_array_len(buf, flex)?;
228 let mut v = Vec::with_capacity(n);
229 for _ in 0..n {
230 v.push(PartitionLogInfo::decode_borrow(buf, version)?);
231 }
232 v
233 };
234 }
235 if flex {
236 out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
237 }
238 Ok(out)
239 }
240}
241#[cfg(test)]
242impl TopicPartitionLogInfo<'_> {
243 #[must_use]
244 pub fn populated(version: i16) -> Self {
245 let mut m = Self::default();
246 if version >= 0 {
247 m.topic_id = crate::primitives::uuid::Uuid([1u8; 16]);
248 }
249 if version >= 0 {
250 m.partition_log_info = vec![PartitionLogInfo::populated(version)];
251 }
252 m
253 }
254}
255#[derive(Debug, Clone, PartialEq, Eq, Default)]
256pub struct PartitionLogInfo<'a> {
257 pub partition: i32,
258 pub last_written_leader_epoch: i32,
259 pub current_leader_epoch: i32,
260 pub log_end_offset: i64,
261 pub error_code: i16,
262 pub error_message: Option<&'a str>,
263 pub unknown_tagged_fields: UnknownTaggedFields,
264}
265impl PartitionLogInfo<'_> {
266 #[must_use]
270 pub fn to_owned(&self) -> crate::owned::get_replica_log_info_response::PartitionLogInfo {
271 crate::owned::get_replica_log_info_response::PartitionLogInfo {
272 partition: (self.partition),
273 last_written_leader_epoch: (self.last_written_leader_epoch),
274 current_leader_epoch: (self.current_leader_epoch),
275 log_end_offset: (self.log_end_offset),
276 error_code: (self.error_code),
277 error_message: (self.error_message).map(std::string::ToString::to_string),
278 unknown_tagged_fields: self.unknown_tagged_fields.clone(),
279 }
280 }
281}
282impl Encode for PartitionLogInfo<'_> {
283 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
284 let flex = version >= 0;
285 if version >= 0 {
286 put_i32(buf, self.partition);
287 }
288 if version >= 0 {
289 put_i32(buf, self.last_written_leader_epoch);
290 }
291 if version >= 0 {
292 put_i32(buf, self.current_leader_epoch);
293 }
294 if version >= 0 {
295 put_i64(buf, self.log_end_offset);
296 }
297 if version >= 0 {
298 put_i16(buf, self.error_code);
299 }
300 if version >= 0 {
301 if flex {
302 let () = put_compact_nullable_string(buf, self.error_message);
303 } else {
304 let () = put_nullable_string(buf, self.error_message);
305 }
306 }
307 if flex {
308 let tagged = WriteTaggedFields::new();
309 tagged.write(buf, &self.unknown_tagged_fields);
310 }
311 Ok(())
312 }
313 fn encoded_len(&self, version: i16) -> usize {
314 let flex = version >= 0;
315 let mut n: usize = 0;
316 if version >= 0 {
317 n += 4;
318 }
319 if version >= 0 {
320 n += 4;
321 }
322 if version >= 0 {
323 n += 4;
324 }
325 if version >= 0 {
326 n += 8;
327 }
328 if version >= 0 {
329 n += 2;
330 }
331 if version >= 0 {
332 n += if flex {
333 compact_nullable_string_len(self.error_message)
334 } else {
335 nullable_string_len(self.error_message)
336 };
337 }
338 if flex {
339 let known_pairs: Vec<(u32, usize)> = Vec::new();
340 n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
341 }
342 n
343 }
344}
345impl<'de> DecodeBorrow<'de> for PartitionLogInfo<'de> {
346 fn decode_borrow(buf: &mut &'de [u8], version: i16) -> Result<Self, ProtocolError> {
347 let flex = version >= 0;
348 let mut out = Self::default();
349 if version >= 0 {
350 out.partition = get_i32(buf)?;
351 }
352 if version >= 0 {
353 out.last_written_leader_epoch = get_i32(buf)?;
354 }
355 if version >= 0 {
356 out.current_leader_epoch = get_i32(buf)?;
357 }
358 if version >= 0 {
359 out.log_end_offset = get_i64(buf)?;
360 }
361 if version >= 0 {
362 out.error_code = get_i16(buf)?;
363 }
364 if version >= 0 {
365 out.error_message = if flex {
366 get_compact_nullable_string_borrowed(buf)?
367 } else {
368 get_nullable_string_borrowed(buf)?
369 };
370 }
371 if flex {
372 out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
373 }
374 Ok(out)
375 }
376}
377#[cfg(test)]
378impl PartitionLogInfo<'_> {
379 #[must_use]
380 pub fn populated(version: i16) -> Self {
381 let mut m = Self::default();
382 if version >= 0 {
383 m.partition = 1i32;
384 }
385 if version >= 0 {
386 m.last_written_leader_epoch = 1i32;
387 }
388 if version >= 0 {
389 m.current_leader_epoch = 1i32;
390 }
391 if version >= 0 {
392 m.log_end_offset = 1i64;
393 }
394 if version >= 0 {
395 m.error_code = 1i16;
396 }
397 if version >= 0 {
398 m.error_message = Some("x");
399 }
400 m
401 }
402}