Skip to main content

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

1// AUTO-GENERATED by crabka-protocol-codegen against a9ce3221537b8653448750697915607dc7936cf3. Do not edit.
2
3use bytes::{Buf, BufMut};
4
5use crate::primitives::fixed::{get_i16, get_i32, put_i16, put_i32};
6use crate::primitives::string_bytes::{
7    compact_string_len, get_compact_string_owned, get_string_owned, put_compact_string, put_string,
8    string_len,
9};
10use crate::{Decode, Encode, ProtocolError, UnknownTaggedFields};
11
12pub const API_KEY: i16 = 47;
13pub const MIN_VERSION: i16 = 0;
14pub const MAX_VERSION: i16 = 0;
15pub const FLEXIBLE_MIN: i16 = 32767;
16
17#[inline]
18fn is_flexible(version: i16) -> bool {
19    version >= FLEXIBLE_MIN
20}
21
22#[derive(Debug, Clone, PartialEq, Eq, Default)]
23pub struct OffsetDeleteResponse {
24    pub error_code: i16,
25    pub throttle_time_ms: i32,
26    pub topics: Vec<OffsetDeleteResponseTopic>,
27    pub unknown_tagged_fields: UnknownTaggedFields,
28}
29impl Encode for OffsetDeleteResponse {
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_i16(buf, self.error_code);
40        }
41        if version >= 0 {
42            put_i32(buf, self.throttle_time_ms);
43        }
44        if version >= 0 {
45            {
46                crate::primitives::array::put_array_len(buf, (self.topics).len(), flex);
47                for it in &self.topics {
48                    it.encode(buf, version)?;
49                }
50            }
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 += 2;
59        }
60        if version >= 0 {
61            n += 4;
62        }
63        if version >= 0 {
64            n += {
65                let prefix =
66                    crate::primitives::array::array_len_prefix_len((self.topics).len(), flex);
67                let body: usize = (self.topics).iter().map(|it| it.encoded_len(version)).sum();
68                prefix + body
69            };
70        }
71        n
72    }
73}
74impl Decode<'_> for OffsetDeleteResponse {
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.error_code = get_i16(buf)?;
86        }
87        if version >= 0 {
88            out.throttle_time_ms = get_i32(buf)?;
89        }
90        if version >= 0 {
91            out.topics = {
92                let n = crate::primitives::array::get_array_len(buf, flex)?;
93                let mut v = Vec::with_capacity(n);
94                for _ in 0..n {
95                    v.push(OffsetDeleteResponseTopic::decode(buf, version)?);
96                }
97                v
98            };
99        }
100        Ok(out)
101    }
102}
103#[cfg(test)]
104impl OffsetDeleteResponse {
105    #[must_use]
106    pub fn populated(version: i16) -> Self {
107        let mut m = Self::default();
108        if version >= 0 {
109            m.error_code = 1i16;
110        }
111        if version >= 0 {
112            m.throttle_time_ms = 1i32;
113        }
114        if version >= 0 {
115            m.topics = vec![OffsetDeleteResponseTopic::populated(version)];
116        }
117        m
118    }
119}
120#[derive(Debug, Clone, PartialEq, Eq, Default)]
121pub struct OffsetDeleteResponseTopic {
122    pub name: String,
123    pub partitions: Vec<OffsetDeleteResponsePartition>,
124    pub unknown_tagged_fields: UnknownTaggedFields,
125}
126impl Encode for OffsetDeleteResponseTopic {
127    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
128        let flex = version >= 32767;
129        if version >= 0 {
130            if flex {
131                put_compact_string(buf, &self.name);
132            } else {
133                put_string(buf, &self.name);
134            }
135        }
136        if version >= 0 {
137            {
138                crate::primitives::array::put_array_len(buf, (self.partitions).len(), flex);
139                for it in &self.partitions {
140                    it.encode(buf, version)?;
141                }
142            }
143        }
144        Ok(())
145    }
146    fn encoded_len(&self, version: i16) -> usize {
147        let flex = version >= 32767;
148        let mut n: usize = 0;
149        if version >= 0 {
150            n += if flex {
151                compact_string_len(&self.name)
152            } else {
153                string_len(&self.name)
154            };
155        }
156        if version >= 0 {
157            n += {
158                let prefix =
159                    crate::primitives::array::array_len_prefix_len((self.partitions).len(), flex);
160                let body: usize = (self.partitions)
161                    .iter()
162                    .map(|it| it.encoded_len(version))
163                    .sum();
164                prefix + body
165            };
166        }
167        n
168    }
169}
170impl Decode<'_> for OffsetDeleteResponseTopic {
171    fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
172        let flex = version >= 32767;
173        let mut out = Self::default();
174        if version >= 0 {
175            out.name = if flex {
176                get_compact_string_owned(buf)?
177            } else {
178                get_string_owned(buf)?
179            };
180        }
181        if version >= 0 {
182            out.partitions = {
183                let n = crate::primitives::array::get_array_len(buf, flex)?;
184                let mut v = Vec::with_capacity(n);
185                for _ in 0..n {
186                    v.push(OffsetDeleteResponsePartition::decode(buf, version)?);
187                }
188                v
189            };
190        }
191        Ok(out)
192    }
193}
194#[cfg(test)]
195impl OffsetDeleteResponseTopic {
196    #[must_use]
197    pub fn populated(version: i16) -> Self {
198        let mut m = Self::default();
199        if version >= 0 {
200            m.name = "x".to_string();
201        }
202        if version >= 0 {
203            m.partitions = vec![OffsetDeleteResponsePartition::populated(version)];
204        }
205        m
206    }
207}
208#[derive(Debug, Clone, PartialEq, Eq, Default)]
209pub struct OffsetDeleteResponsePartition {
210    pub partition_index: i32,
211    pub error_code: i16,
212    pub unknown_tagged_fields: UnknownTaggedFields,
213}
214impl Encode for OffsetDeleteResponsePartition {
215    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
216        let flex = version >= 32767;
217        if version >= 0 {
218            put_i32(buf, self.partition_index);
219        }
220        if version >= 0 {
221            put_i16(buf, self.error_code);
222        }
223        Ok(())
224    }
225    fn encoded_len(&self, version: i16) -> usize {
226        let flex = version >= 32767;
227        let mut n: usize = 0;
228        if version >= 0 {
229            n += 4;
230        }
231        if version >= 0 {
232            n += 2;
233        }
234        n
235    }
236}
237impl Decode<'_> for OffsetDeleteResponsePartition {
238    fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
239        let flex = version >= 32767;
240        let mut out = Self::default();
241        if version >= 0 {
242            out.partition_index = get_i32(buf)?;
243        }
244        if version >= 0 {
245            out.error_code = get_i16(buf)?;
246        }
247        Ok(out)
248    }
249}
250#[cfg(test)]
251impl OffsetDeleteResponsePartition {
252    #[must_use]
253    pub fn populated(version: i16) -> Self {
254        let mut m = Self::default();
255        if version >= 0 {
256            m.partition_index = 1i32;
257        }
258        if version >= 0 {
259            m.error_code = 1i16;
260        }
261        m
262    }
263}
264
265/// Default JSON payload matching `Self::default()` for JVM oracle differential testing.
266/// Only includes fields valid for the given version.
267#[must_use]
268#[allow(unused_comparisons)]
269pub fn default_json(version: i16) -> ::serde_json::Value {
270    let mut obj = ::serde_json::Map::new();
271    obj.insert("errorCode".to_string(), ::serde_json::json!(0));
272    obj.insert("throttleTimeMs".to_string(), ::serde_json::json!(0));
273    obj.insert("topics".to_string(), ::serde_json::Value::Array(vec![]));
274    ::serde_json::Value::Object(obj)
275}