Skip to main content

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

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