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