Skip to main content

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