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