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