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