Skip to main content

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

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