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