Skip to main content

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

1// AUTO-GENERATED by crabka-protocol-codegen against a9ce3221537b8653448750697915607dc7936cf3. Do not edit.
2
3use bytes::{Buf, BufMut};
4
5use crate::primitives::fixed::{get_i16, get_i32, get_i8, put_i16, put_i32, put_i8};
6use crate::primitives::string_bytes::{
7    compact_string_len, get_compact_string_owned, get_string_owned,
8    put_compact_string, put_string, string_len,
9};
10use crate::tagged_fields::{read_tagged_fields, tagged_fields_len, WriteTaggedFields};
11use crate::{Decode, Encode, ProtocolError, UnknownTaggedFields};
12
13pub const API_KEY: i16 = 74;
14pub const MIN_VERSION: i16 = 0;
15pub const MAX_VERSION: i16 = 1;
16pub const FLEXIBLE_MIN: i16 = 0;
17
18#[inline]
19fn is_flexible(version: i16) -> bool { version >= FLEXIBLE_MIN }
20
21#[derive(Debug, Clone, PartialEq, Eq, Default)]
22pub struct ListConfigResourcesResponse {
23    pub throttle_time_ms: i32,
24    pub error_code: i16,
25    pub config_resources: Vec<ConfigResource>,
26    pub unknown_tagged_fields: UnknownTaggedFields,
27}
28
29impl Encode for ListConfigResourcesResponse {
30    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
31        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
32            return Err(ProtocolError::UnsupportedVersion { api_key: API_KEY, version });
33        }
34        let flex = is_flexible(version);
35        if version >= 0 { put_i32(buf, self.throttle_time_ms) }
36        if version >= 0 { put_i16(buf, self.error_code) }
37        if version >= 0 { { crate::primitives::array::put_array_len(buf, (self.config_resources).len(), flex); for it in &self.config_resources { it.encode(buf, version)?; } } }
38        if flex {
39            let tagged = WriteTaggedFields::new();
40            tagged.write(buf, &self.unknown_tagged_fields);
41        }
42        Ok(())
43    }
44    fn encoded_len(&self, version: i16) -> usize {
45        let flex = is_flexible(version);
46        let mut n: usize = 0;
47        if version >= 0 { n += 4; }
48        if version >= 0 { n += 2; }
49        if version >= 0 { n += { let prefix = crate::primitives::array::array_len_prefix_len((self.config_resources).len(), flex); let body: usize = (self.config_resources).iter().map(|it| it.encoded_len(version)).sum(); prefix + body }; }
50        if flex {
51            let known_pairs: Vec<(u32, usize)> = Vec::new();
52            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
53        }
54        n
55    }
56}
57
58impl<'de> Decode<'de> for ListConfigResourcesResponse {
59    fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
60        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
61            return Err(ProtocolError::UnsupportedVersion { api_key: API_KEY, version });
62        }
63        let flex = is_flexible(version);
64        let mut out = Self::default();
65        if version >= 0 { out.throttle_time_ms = get_i32(buf)?; }
66        if version >= 0 { out.error_code = get_i16(buf)?; }
67        if version >= 0 { out.config_resources = { let n = crate::primitives::array::get_array_len(buf, flex)?; let mut v = Vec::with_capacity(n); for _ in 0..n { v.push(ConfigResource::decode(buf, version)?); } v }; }
68        if flex {
69            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| {
70                Ok(false)
71            })?;
72        }
73        Ok(out)
74    }
75}
76
77#[derive(Debug, Clone, PartialEq, Eq)]
78pub struct ConfigResource {
79    pub resource_name: String,
80    pub resource_type: i8,
81    pub unknown_tagged_fields: UnknownTaggedFields,
82}
83
84impl Default for ConfigResource {
85    fn default() -> Self {
86        Self {
87            resource_name: String::new(),
88            resource_type: 16i8,
89            unknown_tagged_fields: Default::default(),
90        }
91    }
92}
93
94impl Encode for ConfigResource {
95    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
96        let flex = version >= 0;
97        if version >= 0 { if flex { put_compact_string(buf, &self.resource_name) } else { put_string(buf, &self.resource_name) } }
98        if version >= 1 { put_i8(buf, self.resource_type) }
99        if flex {
100            let tagged = WriteTaggedFields::new();
101            tagged.write(buf, &self.unknown_tagged_fields);
102        }
103        Ok(())
104    }
105    fn encoded_len(&self, version: i16) -> usize {
106        let flex = version >= 0;
107        let mut n: usize = 0;
108        if version >= 0 { n += if flex { compact_string_len(&self.resource_name) } else { string_len(&self.resource_name) }; }
109        if version >= 1 { n += 1; }
110        if flex {
111            let known_pairs: Vec<(u32, usize)> = Vec::new();
112            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
113        }
114        n
115    }
116}
117
118impl<'de> Decode<'de> for ConfigResource {
119    fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
120        let flex = version >= 0;
121        let mut out = Self::default();
122        if version >= 0 { out.resource_name = if flex { get_compact_string_owned(buf)? } else { get_string_owned(buf)? }; }
123        if version >= 1 { out.resource_type = get_i8(buf)?; }
124        if flex {
125            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| {
126                Ok(false)
127            })?;
128        }
129        Ok(out)
130    }
131}
132
133/// Default JSON payload matching `Self::default()` for JVM oracle differential testing.
134/// Only includes fields valid for the given version.
135#[must_use]
136#[allow(unused_comparisons)]
137pub fn default_json(version: i16) -> ::serde_json::Value {
138    let mut obj = ::serde_json::Map::new();
139    obj.insert("throttleTimeMs".to_string(), ::serde_json::json!(0));
140    obj.insert("errorCode".to_string(), ::serde_json::json!(0));
141    obj.insert("configResources".to_string(), ::serde_json::Value::Array(vec![]));
142    ::serde_json::Value::Object(obj)
143}