Skip to main content

crabka_protocol/opt/rustwide/workdir/generated/
AlterPartitionReassignmentsRequest.borrowed.rs

1// AUTO-GENERATED by crabka-protocol-codegen against a9ce3221537b8653448750697915607dc7936cf3. Do not edit.
2
3use bytes::BufMut;
4
5use crate::primitives::fixed::{get_bool, get_i32, put_bool, put_i32};
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 = 45;
16pub const MIN_VERSION: i16 = 0;
17pub const MAX_VERSION: i16 = 1;
18pub const FLEXIBLE_MIN: i16 = 0;
19
20#[inline]
21fn is_flexible(version: i16) -> bool { version >= FLEXIBLE_MIN }
22
23#[derive(Debug, Clone, PartialEq, Eq)]
24pub struct AlterPartitionReassignmentsRequest<'a> {
25    pub timeout_ms: i32,
26    pub allow_replication_factor_change: bool,
27    pub topics: Vec<ReassignableTopic<'a>>,
28    pub unknown_tagged_fields: UnknownTaggedFields,
29}
30
31impl<'a> Default for AlterPartitionReassignmentsRequest<'a> {
32    fn default() -> Self {
33        Self {
34            timeout_ms: 60_000i32,
35            allow_replication_factor_change: true,
36            topics: Vec::new(),
37            unknown_tagged_fields: Default::default(),
38        }
39    }
40}
41
42impl<'a> AlterPartitionReassignmentsRequest<'a> {
43    pub fn to_owned(&self) -> crate::owned::alter_partition_reassignments_request::AlterPartitionReassignmentsRequest {
44        crate::owned::alter_partition_reassignments_request::AlterPartitionReassignmentsRequest {
45            timeout_ms: (self.timeout_ms),
46            allow_replication_factor_change: (self.allow_replication_factor_change),
47            topics: (self.topics).iter().map(|it| it.to_owned()).collect(),
48            unknown_tagged_fields: self.unknown_tagged_fields.clone(),
49        }
50    }
51}
52
53impl<'a> Encode for AlterPartitionReassignmentsRequest<'a> {
54    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
55        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
56            return Err(ProtocolError::UnsupportedVersion { api_key: API_KEY, version });
57        }
58        let flex = is_flexible(version);
59        if version >= 0 { put_i32(buf, self.timeout_ms) }
60        if version >= 1 { put_bool(buf, self.allow_replication_factor_change) }
61        if version >= 0 { { crate::primitives::array::put_array_len(buf, (self.topics).len(), flex); for it in &self.topics { it.encode(buf, version)?; } } }
62        if flex {
63            let tagged = WriteTaggedFields::new();
64            tagged.write(buf, &self.unknown_tagged_fields);
65        }
66        Ok(())
67    }
68    fn encoded_len(&self, version: i16) -> usize {
69        let flex = is_flexible(version);
70        let mut n: usize = 0;
71        if version >= 0 { n += 4; }
72        if version >= 1 { n += 1; }
73        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 }; }
74        if flex {
75            let known_pairs: Vec<(u32, usize)> = Vec::new();
76            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
77        }
78        n
79    }
80}
81
82impl<'de> DecodeBorrow<'de> for AlterPartitionReassignmentsRequest<'de> {
83    fn decode_borrow(buf: &mut &'de [u8], version: i16) -> Result<Self, ProtocolError> {
84        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
85            return Err(ProtocolError::UnsupportedVersion { api_key: API_KEY, version });
86        }
87        let flex = is_flexible(version);
88        let mut out = Self::default();
89        if version >= 0 { out.timeout_ms = get_i32(buf)?; }
90        if version >= 1 { out.allow_replication_factor_change = get_bool(buf)?; }
91        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_borrow(buf, version)?); } v }; }
92        if flex {
93            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| {
94                Ok(false)
95            })?;
96        }
97        Ok(out)
98    }
99}
100
101#[derive(Debug, Clone, PartialEq, Eq)]
102pub struct ReassignableTopic<'a> {
103    pub name: &'a str,
104    pub partitions: Vec<ReassignablePartition>,
105    pub unknown_tagged_fields: UnknownTaggedFields,
106}
107
108impl<'a> Default for ReassignableTopic<'a> {
109    fn default() -> Self {
110        Self {
111            name: "",
112            partitions: Vec::new(),
113            unknown_tagged_fields: Default::default(),
114        }
115    }
116}
117
118impl<'a> ReassignableTopic<'a> {
119    pub fn to_owned(&self) -> crate::owned::alter_partition_reassignments_request::ReassignableTopic {
120        crate::owned::alter_partition_reassignments_request::ReassignableTopic {
121            name: (self.name).to_string(),
122            partitions: (self.partitions).iter().map(|it| it.to_owned()).collect(),
123            unknown_tagged_fields: self.unknown_tagged_fields.clone(),
124        }
125    }
126}
127
128impl<'a> Encode for ReassignableTopic<'a> {
129    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
130        let flex = version >= 0;
131        if version >= 0 { if flex { put_compact_string(buf, self.name) } else { put_string(buf, self.name) } }
132        if version >= 0 { { crate::primitives::array::put_array_len(buf, (self.partitions).len(), flex); for it in &self.partitions { it.encode(buf, version)?; } } }
133        if flex {
134            let tagged = WriteTaggedFields::new();
135            tagged.write(buf, &self.unknown_tagged_fields);
136        }
137        Ok(())
138    }
139    fn encoded_len(&self, version: i16) -> usize {
140        let flex = version >= 0;
141        let mut n: usize = 0;
142        if version >= 0 { n += if flex { compact_string_len(self.name) } else { string_len(self.name) }; }
143        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 }; }
144        if flex {
145            let known_pairs: Vec<(u32, usize)> = Vec::new();
146            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
147        }
148        n
149    }
150}
151
152impl<'de> DecodeBorrow<'de> for ReassignableTopic<'de> {
153    fn decode_borrow(buf: &mut &'de [u8], version: i16) -> Result<Self, ProtocolError> {
154        let flex = version >= 0;
155        let mut out = Self::default();
156        if version >= 0 { out.name = if flex { get_compact_string_borrowed(buf)? } else { get_string_borrowed(buf)? }; }
157        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_borrow(buf, version)?); } v }; }
158        if flex {
159            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| {
160                Ok(false)
161            })?;
162        }
163        Ok(out)
164    }
165}
166
167#[derive(Debug, Clone, PartialEq, Eq)]
168pub struct ReassignablePartition {
169    pub partition_index: i32,
170    pub replicas: Option<Vec<i32>>,
171    pub unknown_tagged_fields: UnknownTaggedFields,
172}
173
174impl Default for ReassignablePartition {
175    fn default() -> Self {
176        Self {
177            partition_index: 0i32,
178            replicas: None,
179            unknown_tagged_fields: Default::default(),
180        }
181    }
182}
183
184impl ReassignablePartition {
185    pub fn to_owned(&self) -> crate::owned::alter_partition_reassignments_request::ReassignablePartition {
186        crate::owned::alter_partition_reassignments_request::ReassignablePartition {
187            partition_index: (self.partition_index),
188            replicas: (self.replicas).clone(),
189            unknown_tagged_fields: self.unknown_tagged_fields.clone(),
190        }
191    }
192}
193
194impl Encode for ReassignablePartition {
195    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
196        let flex = version >= 0;
197        if version >= 0 { put_i32(buf, self.partition_index) }
198        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); } } } }
199        if flex {
200            let tagged = WriteTaggedFields::new();
201            tagged.write(buf, &self.unknown_tagged_fields);
202        }
203        Ok(())
204    }
205    fn encoded_len(&self, version: i16) -> usize {
206        let flex = version >= 0;
207        let mut n: usize = 0;
208        if version >= 0 { n += 4; }
209        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 }; }
210        if flex {
211            let known_pairs: Vec<(u32, usize)> = Vec::new();
212            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
213        }
214        n
215    }
216}
217
218impl<'de> DecodeBorrow<'de> for ReassignablePartition {
219    fn decode_borrow(buf: &mut &'de [u8], version: i16) -> Result<Self, ProtocolError> {
220        let flex = version >= 0;
221        let mut out = Self::default();
222        if version >= 0 { out.partition_index = get_i32(buf)?; }
223        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) } } }; }
224        if flex {
225            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| {
226                Ok(false)
227            })?;
228        }
229        Ok(out)
230    }
231}