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