Skip to main content

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

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