Skip to main content

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