Skip to main content

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