Skip to main content

krabka_protocol/opt/rustwide/workdir/generated/
DescribeProducersRequest.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 = 61;
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, Default)]
27pub struct DescribeProducersRequest {
28    pub topics: Vec<TopicRequest>,
29    pub unknown_tagged_fields: UnknownTaggedFields,
30}
31impl Encode for DescribeProducersRequest {
32    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
33        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
34            return Err(ProtocolError::UnsupportedVersion {
35                api_key: API_KEY,
36                version,
37            });
38        }
39        let flex = is_flexible(version);
40        if version >= 0 {
41            {
42                crate::primitives::array::put_array_len(buf, (self.topics).len(), flex);
43                for it in &self.topics {
44                    it.encode(buf, version)?;
45                }
46            };
47        }
48        if flex {
49            let tagged = WriteTaggedFields::new();
50            tagged.write(buf, &self.unknown_tagged_fields);
51        }
52        Ok(())
53    }
54    fn encoded_len(&self, version: i16) -> usize {
55        let flex = is_flexible(version);
56        let mut n: usize = 0;
57        if version >= 0 {
58            n += {
59                let prefix =
60                    crate::primitives::array::array_len_prefix_len((self.topics).len(), flex);
61                let body: usize = (self.topics).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 DescribeProducersRequest {
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 n = crate::primitives::array::get_array_len(buf, flex)?;
85                let mut v = Vec::with_capacity(n);
86                for _ in 0..n {
87                    v.push(TopicRequest::decode(buf, version)?);
88                }
89                v
90            };
91        }
92        if flex {
93            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
94        }
95        Ok(out)
96    }
97}
98#[cfg(test)]
99impl DescribeProducersRequest {
100    #[must_use]
101    pub fn populated(version: i16) -> Self {
102        let mut m = Self::default();
103        if version >= 0 {
104            m.topics = vec![TopicRequest::populated(version)];
105        }
106        m
107    }
108}
109#[derive(Debug, Clone, PartialEq, Eq, Default)]
110pub struct TopicRequest {
111    pub name: String,
112    pub partition_indexes: Vec<i32>,
113    pub unknown_tagged_fields: UnknownTaggedFields,
114}
115impl Encode for TopicRequest {
116    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
117        let flex = version >= 0;
118        if version >= 0 {
119            if flex {
120                let () = put_compact_string(buf, &self.name);
121            } else {
122                let () = put_string(buf, &self.name);
123            }
124        }
125        if version >= 0 {
126            {
127                crate::primitives::array::put_array_len(buf, (self.partition_indexes).len(), flex);
128                for it in &self.partition_indexes {
129                    put_i32(buf, *it);
130                }
131            };
132        }
133        if flex {
134            let tagged = WriteTaggedFields::new();
135            tagged.write(buf, &self.unknown_tagged_fields);
136        }
137        Ok(())
138    }
139    fn encoded_len(&self, version: i16) -> usize {
140        let flex = version >= 0;
141        let mut n: usize = 0;
142        if version >= 0 {
143            n += if flex {
144                compact_string_len(&self.name)
145            } else {
146                string_len(&self.name)
147            };
148        }
149        if version >= 0 {
150            n += {
151                let prefix = crate::primitives::array::array_len_prefix_len(
152                    (self.partition_indexes).len(),
153                    flex,
154                );
155                let body: usize = (self.partition_indexes).iter().map(|_| 4).sum();
156                prefix + body
157            };
158        }
159        if flex {
160            let known_pairs: Vec<(u32, usize)> = Vec::new();
161            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
162        }
163        n
164    }
165}
166impl Decode<'_> for TopicRequest {
167    fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
168        let flex = version >= 0;
169        let mut out = Self::default();
170        if version >= 0 {
171            out.name = if flex {
172                get_compact_string_owned(buf)?
173            } else {
174                get_string_owned(buf)?
175            };
176        }
177        if version >= 0 {
178            out.partition_indexes = {
179                let n = crate::primitives::array::get_array_len(buf, flex)?;
180                let mut v = Vec::with_capacity(n);
181                for _ in 0..n {
182                    v.push(get_i32(buf)?);
183                }
184                v
185            };
186        }
187        if flex {
188            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
189        }
190        Ok(out)
191    }
192}
193#[cfg(test)]
194impl TopicRequest {
195    #[must_use]
196    pub fn populated(version: i16) -> Self {
197        let mut m = Self::default();
198        if version >= 0 {
199            m.name = "x".to_string();
200        }
201        if version >= 0 {
202            m.partition_indexes = vec![1i32];
203        }
204        m
205    }
206}
207/// Default JSON payload matching `Self::default()` for JVM oracle differential testing.
208/// Only includes fields valid for the given version.
209#[must_use]
210#[allow(unused_comparisons)]
211pub fn default_json(_version: i16) -> ::serde_json::Value {
212    let mut obj = ::serde_json::Map::new();
213    obj.insert("topics".to_string(), ::serde_json::Value::Array(vec![]));
214    ::serde_json::Value::Object(obj)
215}
216impl crate::ProtocolRequest for DescribeProducersRequest {
217    const API_KEY: i16 = API_KEY;
218    const MIN_VERSION: i16 = MIN_VERSION;
219    const MAX_VERSION: i16 = MAX_VERSION;
220    const LATEST_STABLE_VERSION: i16 = LATEST_STABLE_VERSION;
221    const FLEXIBLE_MIN: i16 = FLEXIBLE_MIN;
222    type Response = super::describe_producers_response::DescribeProducersResponse;
223}