krabka_protocol/opt/rustwide/workdir/generated/
OffsetDeleteRequest.owned.rs1use bytes::{Buf, BufMut};
4
5use crate::{
6 Decode, Encode, ProtocolError, UnknownTaggedFields,
7 primitives::{
8 fixed::{get_i32, 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 LATEST_STABLE_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 OffsetDeleteRequest {
27 pub group_id: String,
28 pub topics: Vec<OffsetDeleteRequestTopic>,
29 pub unknown_tagged_fields: UnknownTaggedFields,
30}
31impl Encode for OffsetDeleteRequest {
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 if flex {
42 let () = put_compact_string(buf, &self.group_id);
43 } else {
44 let () = put_string(buf, &self.group_id);
45 }
46 }
47 if version >= 0 {
48 {
49 crate::primitives::array::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 += if flex {
62 compact_string_len(&self.group_id)
63 } else {
64 string_len(&self.group_id)
65 };
66 }
67 if version >= 0 {
68 n += {
69 let prefix =
70 crate::primitives::array::array_len_prefix_len((self.topics).len(), flex);
71 let body: usize = (self.topics).iter().map(|it| it.encoded_len(version)).sum();
72 prefix + body
73 };
74 }
75 n
76 }
77}
78impl Decode<'_> for OffsetDeleteRequest {
79 fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
80 if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
81 return Err(ProtocolError::UnsupportedVersion {
82 api_key: API_KEY,
83 version,
84 });
85 }
86 let flex = is_flexible(version);
87 let mut out = Self::default();
88 if version >= 0 {
89 out.group_id = if flex {
90 get_compact_string_owned(buf)?
91 } else {
92 get_string_owned(buf)?
93 };
94 }
95 if version >= 0 {
96 out.topics = {
97 let n = crate::primitives::array::get_array_len(buf, flex)?;
98 let mut v = Vec::with_capacity(n);
99 for _ in 0..n {
100 v.push(OffsetDeleteRequestTopic::decode(buf, version)?);
101 }
102 v
103 };
104 }
105 Ok(out)
106 }
107}
108#[cfg(test)]
109impl OffsetDeleteRequest {
110 #[must_use]
111 pub fn populated(version: i16) -> Self {
112 let mut m = Self::default();
113 if version >= 0 {
114 m.group_id = "x".to_string();
115 }
116 if version >= 0 {
117 m.topics = vec![OffsetDeleteRequestTopic::populated(version)];
118 }
119 m
120 }
121}
122#[derive(Debug, Clone, PartialEq, Eq, Default)]
123pub struct OffsetDeleteRequestTopic {
124 pub name: String,
125 pub partitions: Vec<OffsetDeleteRequestPartition>,
126 pub unknown_tagged_fields: UnknownTaggedFields,
127}
128impl Encode for OffsetDeleteRequestTopic {
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 OffsetDeleteRequestTopic {
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(OffsetDeleteRequestPartition::decode(buf, version)?);
189 }
190 v
191 };
192 }
193 Ok(out)
194 }
195}
196#[cfg(test)]
197impl OffsetDeleteRequestTopic {
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![OffsetDeleteRequestPartition::populated(version)];
206 }
207 m
208 }
209}
210#[derive(Debug, Clone, PartialEq, Eq, Default)]
211pub struct OffsetDeleteRequestPartition {
212 pub partition_index: i32,
213 pub unknown_tagged_fields: UnknownTaggedFields,
214}
215impl Encode for OffsetDeleteRequestPartition {
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 Ok(())
221 }
222 fn encoded_len(&self, version: i16) -> usize {
223 let mut n: usize = 0;
224 if version >= 0 {
225 n += 4;
226 }
227 n
228 }
229}
230impl Decode<'_> for OffsetDeleteRequestPartition {
231 fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
232 let mut out = Self::default();
233 if version >= 0 {
234 out.partition_index = get_i32(buf)?;
235 }
236 Ok(out)
237 }
238}
239#[cfg(test)]
240impl OffsetDeleteRequestPartition {
241 #[must_use]
242 pub fn populated(version: i16) -> Self {
243 let mut m = Self::default();
244 if version >= 0 {
245 m.partition_index = 1i32;
246 }
247 m
248 }
249}
250#[must_use]
253#[allow(unused_comparisons)]
254pub fn default_json(_version: i16) -> ::serde_json::Value {
255 let mut obj = ::serde_json::Map::new();
256 obj.insert(
257 "groupId".to_string(),
258 ::serde_json::Value::String(String::new()),
259 );
260 obj.insert("topics".to_string(), ::serde_json::Value::Array(vec![]));
261 ::serde_json::Value::Object(obj)
262}
263impl crate::ProtocolRequest for OffsetDeleteRequest {
264 const API_KEY: i16 = API_KEY;
265 const MIN_VERSION: i16 = MIN_VERSION;
266 const MAX_VERSION: i16 = MAX_VERSION;
267 const LATEST_STABLE_VERSION: i16 = LATEST_STABLE_VERSION;
268 const FLEXIBLE_MIN: i16 = FLEXIBLE_MIN;
269 type Response = super::offset_delete_response::OffsetDeleteResponse;
270}