crabka_protocol/opt/rustwide/workdir/generated/
AlterPartitionReassignmentsRequest.owned.rs1use bytes::{Buf, BufMut};
4
5use crate::primitives::fixed::{get_bool, get_i32, put_bool, put_i32};
6use crate::primitives::string_bytes::{
7 compact_string_len, get_compact_string_owned, get_string_owned,
8 put_compact_string, put_string, string_len,
9};
10use crate::tagged_fields::{read_tagged_fields, tagged_fields_len, WriteTaggedFields};
11use crate::{Decode, Encode, ProtocolError, UnknownTaggedFields};
12
13pub const API_KEY: i16 = 45;
14pub const MIN_VERSION: i16 = 0;
15pub const MAX_VERSION: i16 = 1;
16pub const FLEXIBLE_MIN: i16 = 0;
17
18#[inline]
19fn is_flexible(version: i16) -> bool { version >= FLEXIBLE_MIN }
20
21#[derive(Debug, Clone, PartialEq, Eq)]
22pub struct AlterPartitionReassignmentsRequest {
23 pub timeout_ms: i32,
24 pub allow_replication_factor_change: bool,
25 pub topics: Vec<ReassignableTopic>,
26 pub unknown_tagged_fields: UnknownTaggedFields,
27}
28
29impl Default for AlterPartitionReassignmentsRequest {
30 fn default() -> Self {
31 Self {
32 timeout_ms: 60_000i32,
33 allow_replication_factor_change: true,
34 topics: Vec::new(),
35 unknown_tagged_fields: Default::default(),
36 }
37 }
38}
39
40impl Encode for AlterPartitionReassignmentsRequest {
41 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
42 if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
43 return Err(ProtocolError::UnsupportedVersion { api_key: API_KEY, version });
44 }
45 let flex = is_flexible(version);
46 if version >= 0 { put_i32(buf, self.timeout_ms) }
47 if version >= 1 { put_bool(buf, self.allow_replication_factor_change) }
48 if version >= 0 { { crate::primitives::array::put_array_len(buf, (self.topics).len(), flex); for it in &self.topics { it.encode(buf, version)?; } } }
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 { n += 4; }
59 if version >= 1 { n += 1; }
60 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 }; }
61 if flex {
62 let known_pairs: Vec<(u32, usize)> = Vec::new();
63 n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
64 }
65 n
66 }
67}
68
69impl<'de> Decode<'de> for AlterPartitionReassignmentsRequest {
70 fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
71 if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
72 return Err(ProtocolError::UnsupportedVersion { api_key: API_KEY, version });
73 }
74 let flex = is_flexible(version);
75 let mut out = Self::default();
76 if version >= 0 { out.timeout_ms = get_i32(buf)?; }
77 if version >= 1 { out.allow_replication_factor_change = get_bool(buf)?; }
78 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(ReassignableTopic::decode(buf, version)?); } v }; }
79 if flex {
80 out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| {
81 Ok(false)
82 })?;
83 }
84 Ok(out)
85 }
86}
87
88#[derive(Debug, Clone, PartialEq, Eq, Default)]
89pub struct ReassignableTopic {
90 pub name: String,
91 pub partitions: Vec<ReassignablePartition>,
92 pub unknown_tagged_fields: UnknownTaggedFields,
93}
94
95impl Encode for ReassignableTopic {
96 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
97 let flex = version >= 0;
98 if version >= 0 { if flex { put_compact_string(buf, &self.name) } else { put_string(buf, &self.name) } }
99 if version >= 0 { { crate::primitives::array::put_array_len(buf, (self.partitions).len(), flex); for it in &self.partitions { it.encode(buf, version)?; } } }
100 if flex {
101 let tagged = WriteTaggedFields::new();
102 tagged.write(buf, &self.unknown_tagged_fields);
103 }
104 Ok(())
105 }
106 fn encoded_len(&self, version: i16) -> usize {
107 let flex = version >= 0;
108 let mut n: usize = 0;
109 if version >= 0 { n += if flex { compact_string_len(&self.name) } else { string_len(&self.name) }; }
110 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 }; }
111 if flex {
112 let known_pairs: Vec<(u32, usize)> = Vec::new();
113 n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
114 }
115 n
116 }
117}
118
119impl<'de> Decode<'de> for ReassignableTopic {
120 fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
121 let flex = version >= 0;
122 let mut out = Self::default();
123 if version >= 0 { out.name = if flex { get_compact_string_owned(buf)? } else { get_string_owned(buf)? }; }
124 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(ReassignablePartition::decode(buf, version)?); } v }; }
125 if flex {
126 out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| {
127 Ok(false)
128 })?;
129 }
130 Ok(out)
131 }
132}
133
134#[derive(Debug, Clone, PartialEq, Eq, Default)]
135pub struct ReassignablePartition {
136 pub partition_index: i32,
137 pub replicas: Option<Vec<i32>>,
138 pub unknown_tagged_fields: UnknownTaggedFields,
139}
140
141impl Encode for ReassignablePartition {
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 { { let len = (self.replicas).as_ref().map(Vec::len); crate::primitives::array::put_nullable_array_len(buf, len, flex); if let Some(v) = &self.replicas { for it in v { put_i32(buf, *it); } } } }
146 if flex {
147 let tagged = WriteTaggedFields::new();
148 tagged.write(buf, &self.unknown_tagged_fields);
149 }
150 Ok(())
151 }
152 fn encoded_len(&self, version: i16) -> usize {
153 let flex = version >= 0;
154 let mut n: usize = 0;
155 if version >= 0 { n += 4; }
156 if version >= 0 { n += { let opt: Option<&Vec<_>> = (self.replicas).as_ref(); let prefix = crate::primitives::array::nullable_array_len_prefix_len(opt.map(|v| v.len()), flex); let body: usize = opt.map_or(0, |v| v.iter().map(|_| 4).sum()); prefix + body }; }
157 if flex {
158 let known_pairs: Vec<(u32, usize)> = Vec::new();
159 n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
160 }
161 n
162 }
163}
164
165impl<'de> Decode<'de> for ReassignablePartition {
166 fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
167 let flex = version >= 0;
168 let mut out = Self::default();
169 if version >= 0 { out.partition_index = get_i32(buf)?; }
170 if version >= 0 { out.replicas = { let opt = crate::primitives::array::get_nullable_array_len(buf, flex)?; match opt { None => None, Some(n) => { let mut v = Vec::with_capacity(n); for _ in 0..n { v.push(get_i32(buf)?); } Some(v) } } }; }
171 if flex {
172 out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| {
173 Ok(false)
174 })?;
175 }
176 Ok(out)
177 }
178}
179
180#[must_use]
183#[allow(unused_comparisons)]
184pub fn default_json(version: i16) -> ::serde_json::Value {
185 let mut obj = ::serde_json::Map::new();
186 obj.insert("timeoutMs".to_string(), ::serde_json::json!(60000));
187 if version >= 1 {
188 obj.insert("allowReplicationFactorChange".to_string(), ::serde_json::Value::Bool(true));
189 }
190 obj.insert("topics".to_string(), ::serde_json::Value::Array(vec![]));
191 ::serde_json::Value::Object(obj)
192}
193
194impl crate::ProtocolRequest for AlterPartitionReassignmentsRequest {
195 const API_KEY: i16 = API_KEY;
196 const MIN_VERSION: i16 = MIN_VERSION;
197 const MAX_VERSION: i16 = MAX_VERSION;
198 const FLEXIBLE_MIN: i16 = FLEXIBLE_MIN;
199 type Response = super::alter_partition_reassignments_response::AlterPartitionReassignmentsResponse;
200}