Skip to main content

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

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