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