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