crabka_protocol/opt/rustwide/workdir/generated/
AlterPartitionRequest.owned.rs1use bytes::{Buf, BufMut};
4
5use crate::primitives::fixed::{get_i32, get_i64, get_i8, put_i32, put_i64, put_i8};
6use crate::tagged_fields::{read_tagged_fields, tagged_fields_len, WriteTaggedFields};
7use crate::{Decode, Encode, ProtocolError, UnknownTaggedFields};
8
9pub const API_KEY: i16 = 56;
10pub const MIN_VERSION: i16 = 2;
11pub const MAX_VERSION: i16 = 3;
12pub const FLEXIBLE_MIN: i16 = 0;
13
14#[inline]
15fn is_flexible(version: i16) -> bool { version >= FLEXIBLE_MIN }
16
17#[derive(Debug, Clone, PartialEq, Eq)]
18pub struct AlterPartitionRequest {
19 pub broker_id: i32,
20 pub broker_epoch: i64,
21 pub topics: Vec<TopicData>,
22 pub unknown_tagged_fields: UnknownTaggedFields,
23}
24
25impl Default for AlterPartitionRequest {
26 fn default() -> Self {
27 Self {
28 broker_id: 0i32,
29 broker_epoch: -1i64,
30 topics: Vec::new(),
31 unknown_tagged_fields: Default::default(),
32 }
33 }
34}
35
36impl Encode for AlterPartitionRequest {
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 { api_key: API_KEY, version });
40 }
41 let flex = is_flexible(version);
42 if version >= 0 { put_i32(buf, self.broker_id) }
43 if version >= 0 { put_i64(buf, self.broker_epoch) }
44 if version >= 0 { { crate::primitives::array::put_array_len(buf, (self.topics).len(), flex); for it in &self.topics { it.encode(buf, version)?; } } }
45 if flex {
46 let tagged = WriteTaggedFields::new();
47 tagged.write(buf, &self.unknown_tagged_fields);
48 }
49 Ok(())
50 }
51 fn encoded_len(&self, version: i16) -> usize {
52 let flex = is_flexible(version);
53 let mut n: usize = 0;
54 if version >= 0 { n += 4; }
55 if version >= 0 { n += 8; }
56 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 }; }
57 if flex {
58 let known_pairs: Vec<(u32, usize)> = Vec::new();
59 n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
60 }
61 n
62 }
63}
64
65impl<'de> Decode<'de> for AlterPartitionRequest {
66 fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
67 if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
68 return Err(ProtocolError::UnsupportedVersion { api_key: API_KEY, version });
69 }
70 let flex = is_flexible(version);
71 let mut out = Self::default();
72 if version >= 0 { out.broker_id = get_i32(buf)?; }
73 if version >= 0 { out.broker_epoch = get_i64(buf)?; }
74 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(TopicData::decode(buf, version)?); } v }; }
75 if flex {
76 out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| {
77 Ok(false)
78 })?;
79 }
80 Ok(out)
81 }
82}
83
84#[derive(Debug, Clone, PartialEq, Eq, Default)]
85pub struct TopicData {
86 pub topic_id: crate::primitives::uuid::Uuid,
87 pub partitions: Vec<PartitionData>,
88 pub unknown_tagged_fields: UnknownTaggedFields,
89}
90
91impl Encode for TopicData {
92 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
93 let flex = version >= 0;
94 if version >= 2 { crate::primitives::uuid::put_uuid(buf, self.topic_id) }
95 if version >= 0 { { crate::primitives::array::put_array_len(buf, (self.partitions).len(), flex); for it in &self.partitions { it.encode(buf, version)?; } } }
96 if flex {
97 let tagged = WriteTaggedFields::new();
98 tagged.write(buf, &self.unknown_tagged_fields);
99 }
100 Ok(())
101 }
102 fn encoded_len(&self, version: i16) -> usize {
103 let flex = version >= 0;
104 let mut n: usize = 0;
105 if version >= 2 { n += 16; }
106 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 }; }
107 if flex {
108 let known_pairs: Vec<(u32, usize)> = Vec::new();
109 n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
110 }
111 n
112 }
113}
114
115impl<'de> Decode<'de> for TopicData {
116 fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
117 let flex = version >= 0;
118 let mut out = Self::default();
119 if version >= 2 { out.topic_id = crate::primitives::uuid::get_uuid(buf)?; }
120 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(PartitionData::decode(buf, version)?); } v }; }
121 if flex {
122 out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| {
123 Ok(false)
124 })?;
125 }
126 Ok(out)
127 }
128}
129
130#[derive(Debug, Clone, PartialEq, Eq, Default)]
131pub struct PartitionData {
132 pub partition_index: i32,
133 pub leader_epoch: i32,
134 pub new_isr: Vec<i32>,
135 pub new_isr_with_epochs: Vec<BrokerState>,
136 pub leader_recovery_state: i8,
137 pub partition_epoch: i32,
138 pub unknown_tagged_fields: UnknownTaggedFields,
139}
140
141impl Encode for PartitionData {
142 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
143 let flex = version >= 0;
144 if version >= 0 { put_i32(buf, self.partition_index) }
145 if version >= 0 { put_i32(buf, self.leader_epoch) }
146 if version >= 0 && version <= 2 { { crate::primitives::array::put_array_len(buf, (self.new_isr).len(), flex); for it in &self.new_isr { put_i32(buf, *it); } } }
147 if version >= 3 { { crate::primitives::array::put_array_len(buf, (self.new_isr_with_epochs).len(), flex); for it in &self.new_isr_with_epochs { it.encode(buf, version)?; } } }
148 if version >= 1 { put_i8(buf, self.leader_recovery_state) }
149 if version >= 0 { put_i32(buf, self.partition_epoch) }
150 if flex {
151 let tagged = WriteTaggedFields::new();
152 tagged.write(buf, &self.unknown_tagged_fields);
153 }
154 Ok(())
155 }
156 fn encoded_len(&self, version: i16) -> usize {
157 let flex = version >= 0;
158 let mut n: usize = 0;
159 if version >= 0 { n += 4; }
160 if version >= 0 { n += 4; }
161 if version >= 0 && version <= 2 { n += { let prefix = crate::primitives::array::array_len_prefix_len((self.new_isr).len(), flex); let body: usize = (self.new_isr).iter().map(|_| 4).sum(); prefix + body }; }
162 if version >= 3 { n += { let prefix = crate::primitives::array::array_len_prefix_len((self.new_isr_with_epochs).len(), flex); let body: usize = (self.new_isr_with_epochs).iter().map(|it| it.encoded_len(version)).sum(); prefix + body }; }
163 if version >= 1 { n += 1; }
164 if version >= 0 { n += 4; }
165 if flex {
166 let known_pairs: Vec<(u32, usize)> = Vec::new();
167 n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
168 }
169 n
170 }
171}
172
173impl<'de> Decode<'de> for PartitionData {
174 fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
175 let flex = version >= 0;
176 let mut out = Self::default();
177 if version >= 0 { out.partition_index = get_i32(buf)?; }
178 if version >= 0 { out.leader_epoch = get_i32(buf)?; }
179 if version >= 0 && version <= 2 { out.new_isr = { let n = crate::primitives::array::get_array_len(buf, flex)?; let mut v = Vec::with_capacity(n); for _ in 0..n { v.push(get_i32(buf)?); } v }; }
180 if version >= 3 { out.new_isr_with_epochs = { let n = crate::primitives::array::get_array_len(buf, flex)?; let mut v = Vec::with_capacity(n); for _ in 0..n { v.push(BrokerState::decode(buf, version)?); } v }; }
181 if version >= 1 { out.leader_recovery_state = get_i8(buf)?; }
182 if version >= 0 { out.partition_epoch = get_i32(buf)?; }
183 if flex {
184 out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| {
185 Ok(false)
186 })?;
187 }
188 Ok(out)
189 }
190}
191
192#[derive(Debug, Clone, PartialEq, Eq)]
193pub struct BrokerState {
194 pub broker_id: i32,
195 pub broker_epoch: i64,
196 pub unknown_tagged_fields: UnknownTaggedFields,
197}
198
199impl Default for BrokerState {
200 fn default() -> Self {
201 Self {
202 broker_id: 0i32,
203 broker_epoch: -1i64,
204 unknown_tagged_fields: Default::default(),
205 }
206 }
207}
208
209impl Encode for BrokerState {
210 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
211 let flex = version >= 0;
212 if version >= 3 { put_i32(buf, self.broker_id) }
213 if version >= 3 { put_i64(buf, self.broker_epoch) }
214 if flex {
215 let tagged = WriteTaggedFields::new();
216 tagged.write(buf, &self.unknown_tagged_fields);
217 }
218 Ok(())
219 }
220 fn encoded_len(&self, version: i16) -> usize {
221 let flex = version >= 0;
222 let mut n: usize = 0;
223 if version >= 3 { n += 4; }
224 if version >= 3 { n += 8; }
225 if flex {
226 let known_pairs: Vec<(u32, usize)> = Vec::new();
227 n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
228 }
229 n
230 }
231}
232
233impl<'de> Decode<'de> for BrokerState {
234 fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
235 let flex = version >= 0;
236 let mut out = Self::default();
237 if version >= 3 { out.broker_id = get_i32(buf)?; }
238 if version >= 3 { out.broker_epoch = get_i64(buf)?; }
239 if flex {
240 out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| {
241 Ok(false)
242 })?;
243 }
244 Ok(out)
245 }
246}
247
248#[must_use]
251#[allow(unused_comparisons)]
252pub fn default_json(version: i16) -> ::serde_json::Value {
253 let mut obj = ::serde_json::Map::new();
254 obj.insert("brokerId".to_string(), ::serde_json::json!(0));
255 obj.insert("brokerEpoch".to_string(), ::serde_json::json!(-1));
256 obj.insert("topics".to_string(), ::serde_json::Value::Array(vec![]));
257 ::serde_json::Value::Object(obj)
258}
259
260impl crate::ProtocolRequest for AlterPartitionRequest {
261 const API_KEY: i16 = API_KEY;
262 const MIN_VERSION: i16 = MIN_VERSION;
263 const MAX_VERSION: i16 = MAX_VERSION;
264 const FLEXIBLE_MIN: i16 = FLEXIBLE_MIN;
265 type Response = super::alter_partition_response::AlterPartitionResponse;
266}