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