Skip to main content

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

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