Skip to main content

krabka_protocol/opt/rustwide/workdir/generated/
GetReplicaLogInfoResponse.borrowed.rs

1// AUTO-GENERATED by krabka-protocol-codegen against a9ce3221537b8653448750697915607dc7936cf3. Do not edit.
2use bytes::BufMut;
3
4use crate::{
5    DecodeBorrow, Encode, ProtocolError, UnknownTaggedFields,
6    owned::get_replica_log_info_response,
7    primitives::{
8        array::{array_len_prefix_len, get_array_len, put_array_len},
9        fixed::{get_i16, get_i32, get_i64, put_i16, put_i32, put_i64},
10        string_bytes::{
11            compact_nullable_string_len, nullable_string_len, put_compact_nullable_string,
12            put_nullable_string,
13        },
14        string_bytes_borrowed::{
15            get_compact_nullable_string_borrowed, get_nullable_string_borrowed,
16        },
17        uuid::{Uuid, get_uuid, put_uuid},
18    },
19    tagged_fields::{WriteTaggedFields, read_tagged_fields, tagged_fields_len},
20};
21pub const API_KEY: i16 = 1020;
22pub const MIN_VERSION: i16 = 0;
23pub const MAX_VERSION: i16 = 0;
24pub const FLEXIBLE_MIN: i16 = 0;
25#[inline]
26#[must_use]
27pub fn is_flexible(version: i16) -> bool {
28    version >= FLEXIBLE_MIN
29}
30#[derive(Debug, Clone, PartialEq, Eq, Default)]
31pub struct GetReplicaLogInfoResponse<'a> {
32    pub broker_epoch: i64,
33    pub topic_partition_log_info_list: Vec<TopicPartitionLogInfo<'a>>,
34    pub unknown_tagged_fields: UnknownTaggedFields,
35}
36impl GetReplicaLogInfoResponse<'_> {
37    #[must_use]
38    pub fn to_owned(&self) -> get_replica_log_info_response::GetReplicaLogInfoResponse {
39        get_replica_log_info_response::GetReplicaLogInfoResponse {
40            broker_epoch: (self.broker_epoch),
41            topic_partition_log_info_list: (self.topic_partition_log_info_list)
42                .iter()
43                .map(TopicPartitionLogInfo::to_owned)
44                .collect(),
45            unknown_tagged_fields: self.unknown_tagged_fields.clone(),
46        }
47    }
48}
49impl Encode for GetReplicaLogInfoResponse<'_> {
50    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
51        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
52            return Err(ProtocolError::UnsupportedVersion {
53                api_key: API_KEY,
54                version,
55            });
56        }
57        let flex = is_flexible(version);
58        if version >= 0 {
59            put_i64(buf, self.broker_epoch);
60        }
61        if version >= 0 {
62            {
63                put_array_len(buf, (self.topic_partition_log_info_list).len(), flex)?;
64                for it in &self.topic_partition_log_info_list {
65                    it.encode(buf, version)?;
66                }
67            }
68        }
69        if flex {
70            let tagged = WriteTaggedFields::new();
71            tagged.write(buf, &self.unknown_tagged_fields)?;
72        }
73        Ok(())
74    }
75    fn encoded_len(&self, version: i16) -> usize {
76        let flex = is_flexible(version);
77        let mut n: usize = 0;
78        if version >= 0 {
79            n += 8;
80        }
81        if version >= 0 {
82            n += {
83                let prefix = array_len_prefix_len((self.topic_partition_log_info_list).len(), flex);
84                let body: usize = (self.topic_partition_log_info_list)
85                    .iter()
86                    .map(|it| it.encoded_len(version))
87                    .sum();
88                prefix + body
89            };
90        }
91        if flex {
92            let known_pairs: Vec<(u32, usize)> = Vec::new();
93            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
94        }
95        n
96    }
97}
98impl<'de> DecodeBorrow<'de> for GetReplicaLogInfoResponse<'de> {
99    fn decode_borrow(buf: &mut &'de [u8], version: i16) -> Result<Self, ProtocolError> {
100        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
101            return Err(ProtocolError::UnsupportedVersion {
102                api_key: API_KEY,
103                version,
104            });
105        }
106        let flex = is_flexible(version);
107        let mut out = Self::default();
108        if version >= 0 {
109            out.broker_epoch = get_i64(buf)?;
110        }
111        if version >= 0 {
112            out.topic_partition_log_info_list = {
113                let n = get_array_len(buf, flex)?;
114                let mut v = Vec::with_capacity(n);
115                for _ in 0..n {
116                    v.push(TopicPartitionLogInfo::decode_borrow(buf, version)?);
117                }
118                v
119            };
120        }
121        if flex {
122            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
123        }
124        Ok(out)
125    }
126}
127#[cfg(test)]
128impl GetReplicaLogInfoResponse<'_> {
129    #[must_use]
130    pub fn populated(version: i16) -> Self {
131        let mut m = Self::default();
132        if version >= 0 {
133            m.broker_epoch = 1i64;
134        }
135        if version >= 0 {
136            m.topic_partition_log_info_list = vec![TopicPartitionLogInfo::populated(version)];
137        }
138        m
139    }
140}
141#[derive(Debug, Clone, PartialEq, Eq, Default)]
142pub struct TopicPartitionLogInfo<'a> {
143    pub topic_id: Uuid,
144    pub partition_log_info: Vec<PartitionLogInfo<'a>>,
145    pub unknown_tagged_fields: UnknownTaggedFields,
146}
147impl TopicPartitionLogInfo<'_> {
148    #[must_use]
149    pub fn to_owned(&self) -> get_replica_log_info_response::TopicPartitionLogInfo {
150        get_replica_log_info_response::TopicPartitionLogInfo {
151            topic_id: (self.topic_id),
152            partition_log_info: (self.partition_log_info)
153                .iter()
154                .map(PartitionLogInfo::to_owned)
155                .collect(),
156            unknown_tagged_fields: self.unknown_tagged_fields.clone(),
157        }
158    }
159}
160impl Encode for TopicPartitionLogInfo<'_> {
161    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
162        let flex = version >= 0;
163        if version >= 0 {
164            put_uuid(buf, self.topic_id);
165        }
166        if version >= 0 {
167            {
168                put_array_len(buf, (self.partition_log_info).len(), flex)?;
169                for it in &self.partition_log_info {
170                    it.encode(buf, version)?;
171                }
172            }
173        }
174        if flex {
175            let tagged = WriteTaggedFields::new();
176            tagged.write(buf, &self.unknown_tagged_fields)?;
177        }
178        Ok(())
179    }
180    fn encoded_len(&self, version: i16) -> usize {
181        let flex = version >= 0;
182        let mut n: usize = 0;
183        if version >= 0 {
184            n += 16;
185        }
186        if version >= 0 {
187            n += {
188                let prefix = array_len_prefix_len((self.partition_log_info).len(), flex);
189                let body: usize = (self.partition_log_info)
190                    .iter()
191                    .map(|it| it.encoded_len(version))
192                    .sum();
193                prefix + body
194            };
195        }
196        if flex {
197            let known_pairs: Vec<(u32, usize)> = Vec::new();
198            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
199        }
200        n
201    }
202}
203impl<'de> DecodeBorrow<'de> for TopicPartitionLogInfo<'de> {
204    fn decode_borrow(buf: &mut &'de [u8], version: i16) -> Result<Self, ProtocolError> {
205        let flex = version >= 0;
206        let mut out = Self::default();
207        if version >= 0 {
208            out.topic_id = get_uuid(buf)?;
209        }
210        if version >= 0 {
211            out.partition_log_info = {
212                let n = get_array_len(buf, flex)?;
213                let mut v = Vec::with_capacity(n);
214                for _ in 0..n {
215                    v.push(PartitionLogInfo::decode_borrow(buf, version)?);
216                }
217                v
218            };
219        }
220        if flex {
221            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
222        }
223        Ok(out)
224    }
225}
226#[cfg(test)]
227impl TopicPartitionLogInfo<'_> {
228    #[must_use]
229    pub fn populated(version: i16) -> Self {
230        let mut m = Self::default();
231        if version >= 0 {
232            m.topic_id = Uuid([1u8; 16]);
233        }
234        if version >= 0 {
235            m.partition_log_info = vec![PartitionLogInfo::populated(version)];
236        }
237        m
238    }
239}
240#[derive(Debug, Clone, PartialEq, Eq, Default)]
241pub struct PartitionLogInfo<'a> {
242    pub partition: i32,
243    pub last_written_leader_epoch: i32,
244    pub current_leader_epoch: i32,
245    pub log_end_offset: i64,
246    pub error_code: i16,
247    pub error_message: Option<&'a str>,
248    pub unknown_tagged_fields: UnknownTaggedFields,
249}
250impl PartitionLogInfo<'_> {
251    #[must_use]
252    pub fn to_owned(&self) -> get_replica_log_info_response::PartitionLogInfo {
253        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(str::to_owned),
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}