Skip to main content

krabka_protocol/opt/rustwide/workdir/generated/
ListPartitionReassignmentsRequest.owned.rs

1// AUTO-GENERATED by krabka-protocol-codegen against a9ce3221537b8653448750697915607dc7936cf3. Do not edit.
2
3use bytes::{Buf, BufMut};
4
5use crate::{
6    Decode, Encode, ProtocolError, UnknownTaggedFields,
7    primitives::{
8        fixed::{get_i32, put_i32},
9        string_bytes::{
10            compact_string_len, get_compact_string_owned, get_string_owned, put_compact_string,
11            put_string, string_len,
12        },
13    },
14    tagged_fields::{WriteTaggedFields, read_tagged_fields, tagged_fields_len},
15};
16pub const API_KEY: i16 = 46;
17pub const MIN_VERSION: i16 = 0;
18pub const MAX_VERSION: i16 = 0;
19pub const LATEST_STABLE_VERSION: i16 = 0;
20pub const FLEXIBLE_MIN: i16 = 0;
21#[inline]
22#[must_use]
23pub fn is_flexible(version: i16) -> bool {
24    version >= FLEXIBLE_MIN
25}
26#[derive(Debug, Clone, PartialEq, Eq)]
27pub struct ListPartitionReassignmentsRequest {
28    pub timeout_ms: i32,
29    pub topics: Option<Vec<ListPartitionReassignmentsTopics>>,
30    pub unknown_tagged_fields: UnknownTaggedFields,
31}
32impl Default for ListPartitionReassignmentsRequest {
33    fn default() -> Self {
34        Self {
35            timeout_ms: 60_000i32,
36            topics: None,
37            unknown_tagged_fields: UnknownTaggedFields::default(),
38        }
39    }
40}
41impl Encode for ListPartitionReassignmentsRequest {
42    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
43        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
44            return Err(ProtocolError::UnsupportedVersion {
45                api_key: API_KEY,
46                version,
47            });
48        }
49        let flex = is_flexible(version);
50        if version >= 0 {
51            put_i32(buf, self.timeout_ms);
52        }
53        if version >= 0 {
54            {
55                let len = (self.topics).as_ref().map(Vec::len);
56                crate::primitives::array::put_nullable_array_len(buf, len, flex);
57                if let Some(v) = &self.topics {
58                    for it in v {
59                        it.encode(buf, version)?;
60                    }
61                }
62            };
63        }
64        if flex {
65            let tagged = WriteTaggedFields::new();
66            tagged.write(buf, &self.unknown_tagged_fields);
67        }
68        Ok(())
69    }
70    fn encoded_len(&self, version: i16) -> usize {
71        let flex = is_flexible(version);
72        let mut n: usize = 0;
73        if version >= 0 {
74            n += 4;
75        }
76        if version >= 0 {
77            n += {
78                let opt: Option<&Vec<_>> = (self.topics).as_ref();
79                let prefix = crate::primitives::array::nullable_array_len_prefix_len(
80                    opt.map(std::vec::Vec::len),
81                    flex,
82                );
83                let body: usize =
84                    opt.map_or(0, |v| v.iter().map(|it| it.encoded_len(version)).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 Decode<'_> for ListPartitionReassignmentsRequest {
96    fn decode<B: Buf>(buf: &mut B, 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.timeout_ms = get_i32(buf)?;
107        }
108        if version >= 0 {
109            out.topics = {
110                let opt = crate::primitives::array::get_nullable_array_len(buf, flex)?;
111                match opt {
112                    None => None,
113                    Some(n) => {
114                        let mut v = Vec::with_capacity(n);
115                        for _ in 0..n {
116                            v.push(ListPartitionReassignmentsTopics::decode(buf, version)?);
117                        }
118                        Some(v)
119                    }
120                }
121            };
122        }
123        if flex {
124            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
125        }
126        Ok(out)
127    }
128}
129#[cfg(test)]
130impl ListPartitionReassignmentsRequest {
131    #[must_use]
132    pub fn populated(version: i16) -> Self {
133        let mut m = Self::default();
134        if version >= 0 {
135            m.timeout_ms = 1i32;
136        }
137        if version >= 0 {
138            m.topics = Some(vec![ListPartitionReassignmentsTopics::populated(version)]);
139        }
140        m
141    }
142}
143#[derive(Debug, Clone, PartialEq, Eq, Default)]
144pub struct ListPartitionReassignmentsTopics {
145    pub name: String,
146    pub partition_indexes: Vec<i32>,
147    pub unknown_tagged_fields: UnknownTaggedFields,
148}
149impl Encode for ListPartitionReassignmentsTopics {
150    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
151        let flex = version >= 0;
152        if version >= 0 {
153            if flex {
154                let () = put_compact_string(buf, &self.name);
155            } else {
156                let () = put_string(buf, &self.name);
157            }
158        }
159        if version >= 0 {
160            {
161                crate::primitives::array::put_array_len(buf, (self.partition_indexes).len(), flex);
162                for it in &self.partition_indexes {
163                    put_i32(buf, *it);
164                }
165            };
166        }
167        if flex {
168            let tagged = WriteTaggedFields::new();
169            tagged.write(buf, &self.unknown_tagged_fields);
170        }
171        Ok(())
172    }
173    fn encoded_len(&self, version: i16) -> usize {
174        let flex = version >= 0;
175        let mut n: usize = 0;
176        if version >= 0 {
177            n += if flex {
178                compact_string_len(&self.name)
179            } else {
180                string_len(&self.name)
181            };
182        }
183        if version >= 0 {
184            n += {
185                let prefix = crate::primitives::array::array_len_prefix_len(
186                    (self.partition_indexes).len(),
187                    flex,
188                );
189                let body: usize = (self.partition_indexes).iter().map(|_| 4).sum();
190                prefix + body
191            };
192        }
193        if flex {
194            let known_pairs: Vec<(u32, usize)> = Vec::new();
195            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
196        }
197        n
198    }
199}
200impl Decode<'_> for ListPartitionReassignmentsTopics {
201    fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
202        let flex = version >= 0;
203        let mut out = Self::default();
204        if version >= 0 {
205            out.name = if flex {
206                get_compact_string_owned(buf)?
207            } else {
208                get_string_owned(buf)?
209            };
210        }
211        if version >= 0 {
212            out.partition_indexes = {
213                let n = crate::primitives::array::get_array_len(buf, flex)?;
214                let mut v = Vec::with_capacity(n);
215                for _ in 0..n {
216                    v.push(get_i32(buf)?);
217                }
218                v
219            };
220        }
221        if flex {
222            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
223        }
224        Ok(out)
225    }
226}
227#[cfg(test)]
228impl ListPartitionReassignmentsTopics {
229    #[must_use]
230    pub fn populated(version: i16) -> Self {
231        let mut m = Self::default();
232        if version >= 0 {
233            m.name = "x".to_string();
234        }
235        if version >= 0 {
236            m.partition_indexes = vec![1i32];
237        }
238        m
239    }
240}
241/// Default JSON payload matching `Self::default()` for JVM oracle differential testing.
242/// Only includes fields valid for the given version.
243#[must_use]
244#[allow(unused_comparisons)]
245pub fn default_json(_version: i16) -> ::serde_json::Value {
246    let mut obj = ::serde_json::Map::new();
247    obj.insert("timeoutMs".to_string(), ::serde_json::json!(60_000));
248    obj.insert("topics".to_string(), ::serde_json::Value::Null);
249    ::serde_json::Value::Object(obj)
250}
251impl crate::ProtocolRequest for ListPartitionReassignmentsRequest {
252    const API_KEY: i16 = API_KEY;
253    const MIN_VERSION: i16 = MIN_VERSION;
254    const MAX_VERSION: i16 = MAX_VERSION;
255    const LATEST_STABLE_VERSION: i16 = LATEST_STABLE_VERSION;
256    const FLEXIBLE_MIN: i16 = FLEXIBLE_MIN;
257    type Response =
258        super::list_partition_reassignments_response::ListPartitionReassignmentsResponse;
259}