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