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