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