Skip to main content

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