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