Skip to main content

crabka_protocol/opt/rustwide/workdir/generated/
DescribeLogDirsRequest.owned.rs

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