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