krabka_protocol/opt/rustwide/workdir/generated/
OffsetDeleteResponse.owned.rs1use 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, put_i16, put_i32},
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};
16pub const API_KEY: i16 = 47;
17pub const MIN_VERSION: i16 = 0;
18pub const MAX_VERSION: i16 = 0;
19pub const FLEXIBLE_MIN: i16 = 32767;
20#[inline]
21#[must_use]
22pub fn is_flexible(version: i16) -> bool {
23 version == FLEXIBLE_MIN
24}
25#[derive(Debug, Clone, PartialEq, Eq, Default)]
26pub struct OffsetDeleteResponse {
27 pub error_code: i16,
28 pub throttle_time_ms: i32,
29 pub topics: Vec<OffsetDeleteResponseTopic>,
30 pub unknown_tagged_fields: UnknownTaggedFields,
31}
32impl Encode for OffsetDeleteResponse {
33 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
34 if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
35 return Err(ProtocolError::UnsupportedVersion {
36 api_key: API_KEY,
37 version,
38 });
39 }
40 let flex = is_flexible(version);
41 if version >= 0 {
42 put_i16(buf, self.error_code);
43 }
44 if version >= 0 {
45 put_i32(buf, self.throttle_time_ms);
46 }
47 if version >= 0 {
48 {
49 put_array_len(buf, (self.topics).len(), flex)?;
50 for it in &self.topics {
51 it.encode(buf, version)?;
52 }
53 }
54 }
55 Ok(())
56 }
57 fn encoded_len(&self, version: i16) -> usize {
58 let flex = is_flexible(version);
59 let mut n: usize = 0;
60 if version >= 0 {
61 n += 2;
62 }
63 if version >= 0 {
64 n += 4;
65 }
66 if version >= 0 {
67 n += {
68 let prefix = 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 = 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 put_compact_string(buf, &self.name)?;
134 } else {
135 put_string(buf, &self.name)?;
136 }
137 }
138 if version >= 0 {
139 {
140 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 = array_len_prefix_len((self.partitions).len(), flex);
161 let body: usize = (self.partitions)
162 .iter()
163 .map(|it| it.encoded_len(version))
164 .sum();
165 prefix + body
166 };
167 }
168 n
169 }
170}
171impl Decode<'_> for OffsetDeleteResponseTopic {
172 fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
173 let flex = version == i16::MAX;
174 let mut out = Self::default();
175 if version >= 0 {
176 out.name = if flex {
177 get_compact_string_owned(buf)?
178 } else {
179 get_string_owned(buf)?
180 };
181 }
182 if version >= 0 {
183 out.partitions = {
184 let n = get_array_len(buf, flex)?;
185 let mut v = Vec::with_capacity(n);
186 for _ in 0..n {
187 v.push(OffsetDeleteResponsePartition::decode(buf, version)?);
188 }
189 v
190 };
191 }
192 Ok(out)
193 }
194}
195#[cfg(test)]
196impl OffsetDeleteResponseTopic {
197 #[must_use]
198 pub fn populated(version: i16) -> Self {
199 let mut m = Self::default();
200 if version >= 0 {
201 m.name = "x".to_owned();
202 }
203 if version >= 0 {
204 m.partitions = vec![OffsetDeleteResponsePartition::populated(version)];
205 }
206 m
207 }
208}
209#[derive(Debug, Clone, PartialEq, Eq, Default)]
210pub struct OffsetDeleteResponsePartition {
211 pub partition_index: i32,
212 pub error_code: i16,
213 pub unknown_tagged_fields: UnknownTaggedFields,
214}
215impl Encode for OffsetDeleteResponsePartition {
216 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
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 mut n: usize = 0;
227 if version >= 0 {
228 n += 4;
229 }
230 if version >= 0 {
231 n += 2;
232 }
233 n
234 }
235}
236impl Decode<'_> for OffsetDeleteResponsePartition {
237 fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
238 let mut out = Self::default();
239 if version >= 0 {
240 out.partition_index = get_i32(buf)?;
241 }
242 if version >= 0 {
243 out.error_code = get_i16(buf)?;
244 }
245 Ok(out)
246 }
247}
248#[cfg(test)]
249impl OffsetDeleteResponsePartition {
250 #[must_use]
251 pub fn populated(version: i16) -> Self {
252 let mut m = Self::default();
253 if version >= 0 {
254 m.partition_index = 1i32;
255 }
256 if version >= 0 {
257 m.error_code = 1i16;
258 }
259 m
260 }
261}
262#[must_use]
265#[allow(unused_comparisons)]
266pub fn default_json(_version: i16) -> ::serde_json::Value {
267 let mut obj = ::serde_json::Map::new();
268 obj.insert("errorCode".to_owned(), ::serde_json::json!(0));
269 obj.insert("throttleTimeMs".to_owned(), ::serde_json::json!(0));
270 obj.insert("topics".to_owned(), ::serde_json::Value::Array(vec![]));
271 ::serde_json::Value::Object(obj)
272}