Skip to main content

crabka_protocol/opt/rustwide/workdir/generated/
AlterConfigsRequest.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_bool, get_i8, put_bool, put_i8};
6use crate::primitives::string_bytes::{
7    compact_nullable_string_len, compact_string_len, get_compact_nullable_string_owned,
8    get_compact_string_owned, get_nullable_string_owned, get_string_owned, nullable_string_len,
9    put_compact_nullable_string, put_compact_string, put_nullable_string, put_string,
10    string_len,
11};
12use crate::tagged_fields::{read_tagged_fields, tagged_fields_len, WriteTaggedFields};
13use crate::{Decode, Encode, ProtocolError, UnknownTaggedFields};
14
15pub const API_KEY: i16 = 33;
16pub const MIN_VERSION: i16 = 0;
17pub const MAX_VERSION: i16 = 2;
18pub const FLEXIBLE_MIN: i16 = 2;
19
20#[inline]
21fn is_flexible(version: i16) -> bool { version >= FLEXIBLE_MIN }
22
23#[derive(Debug, Clone, PartialEq, Eq, Default)]
24pub struct AlterConfigsRequest {
25    pub resources: Vec<AlterConfigsResource>,
26    pub validate_only: bool,
27    pub unknown_tagged_fields: UnknownTaggedFields,
28}
29
30impl Encode for AlterConfigsRequest {
31    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
32        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
33            return Err(ProtocolError::UnsupportedVersion { api_key: API_KEY, version });
34        }
35        let flex = is_flexible(version);
36        if version >= 0 { { crate::primitives::array::put_array_len(buf, (self.resources).len(), flex); for it in &self.resources { it.encode(buf, version)?; } } }
37        if version >= 0 { put_bool(buf, self.validate_only) }
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 += { let prefix = crate::primitives::array::array_len_prefix_len((self.resources).len(), flex); let body: usize = (self.resources).iter().map(|it| it.encoded_len(version)).sum(); prefix + body }; }
48        if version >= 0 { n += 1; }
49        if flex {
50            let known_pairs: Vec<(u32, usize)> = Vec::new();
51            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
52        }
53        n
54    }
55}
56
57impl<'de> Decode<'de> for AlterConfigsRequest {
58    fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
59        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
60            return Err(ProtocolError::UnsupportedVersion { api_key: API_KEY, version });
61        }
62        let flex = is_flexible(version);
63        let mut out = Self::default();
64        if version >= 0 { out.resources = { let n = crate::primitives::array::get_array_len(buf, flex)?; let mut v = Vec::with_capacity(n); for _ in 0..n { v.push(AlterConfigsResource::decode(buf, version)?); } v }; }
65        if version >= 0 { out.validate_only = get_bool(buf)?; }
66        if flex {
67            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| {
68                Ok(false)
69            })?;
70        }
71        Ok(out)
72    }
73}
74
75#[derive(Debug, Clone, PartialEq, Eq, Default)]
76pub struct AlterConfigsResource {
77    pub resource_type: i8,
78    pub resource_name: String,
79    pub configs: Vec<AlterableConfig>,
80    pub unknown_tagged_fields: UnknownTaggedFields,
81}
82
83impl Encode for AlterConfigsResource {
84    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
85        let flex = version >= 2;
86        if version >= 0 { put_i8(buf, self.resource_type) }
87        if version >= 0 { if flex { put_compact_string(buf, &self.resource_name) } else { put_string(buf, &self.resource_name) } }
88        if version >= 0 { { crate::primitives::array::put_array_len(buf, (self.configs).len(), flex); for it in &self.configs { it.encode(buf, version)?; } } }
89        if flex {
90            let tagged = WriteTaggedFields::new();
91            tagged.write(buf, &self.unknown_tagged_fields);
92        }
93        Ok(())
94    }
95    fn encoded_len(&self, version: i16) -> usize {
96        let flex = version >= 2;
97        let mut n: usize = 0;
98        if version >= 0 { n += 1; }
99        if version >= 0 { n += if flex { compact_string_len(&self.resource_name) } else { string_len(&self.resource_name) }; }
100        if version >= 0 { n += { let prefix = crate::primitives::array::array_len_prefix_len((self.configs).len(), flex); let body: usize = (self.configs).iter().map(|it| it.encoded_len(version)).sum(); prefix + body }; }
101        if flex {
102            let known_pairs: Vec<(u32, usize)> = Vec::new();
103            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
104        }
105        n
106    }
107}
108
109impl<'de> Decode<'de> for AlterConfigsResource {
110    fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
111        let flex = version >= 2;
112        let mut out = Self::default();
113        if version >= 0 { out.resource_type = get_i8(buf)?; }
114        if version >= 0 { out.resource_name = if flex { get_compact_string_owned(buf)? } else { get_string_owned(buf)? }; }
115        if version >= 0 { out.configs = { let n = crate::primitives::array::get_array_len(buf, flex)?; let mut v = Vec::with_capacity(n); for _ in 0..n { v.push(AlterableConfig::decode(buf, version)?); } v }; }
116        if flex {
117            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| {
118                Ok(false)
119            })?;
120        }
121        Ok(out)
122    }
123}
124
125#[derive(Debug, Clone, PartialEq, Eq, Default)]
126pub struct AlterableConfig {
127    pub name: String,
128    pub value: Option<String>,
129    pub unknown_tagged_fields: UnknownTaggedFields,
130}
131
132impl Encode for AlterableConfig {
133    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
134        let flex = version >= 2;
135        if version >= 0 { if flex { put_compact_string(buf, &self.name) } else { put_string(buf, &self.name) } }
136        if version >= 0 { if flex { put_compact_nullable_string(buf, self.value.as_deref()) } else { put_nullable_string(buf, self.value.as_deref()) } }
137        if flex {
138            let tagged = WriteTaggedFields::new();
139            tagged.write(buf, &self.unknown_tagged_fields);
140        }
141        Ok(())
142    }
143    fn encoded_len(&self, version: i16) -> usize {
144        let flex = version >= 2;
145        let mut n: usize = 0;
146        if version >= 0 { n += if flex { compact_string_len(&self.name) } else { string_len(&self.name) }; }
147        if version >= 0 { n += if flex { compact_nullable_string_len(self.value.as_deref()) } else { nullable_string_len(self.value.as_deref()) }; }
148        if flex {
149            let known_pairs: Vec<(u32, usize)> = Vec::new();
150            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
151        }
152        n
153    }
154}
155
156impl<'de> Decode<'de> for AlterableConfig {
157    fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
158        let flex = version >= 2;
159        let mut out = Self::default();
160        if version >= 0 { out.name = if flex { get_compact_string_owned(buf)? } else { get_string_owned(buf)? }; }
161        if version >= 0 { out.value = if flex { get_compact_nullable_string_owned(buf)? } else { get_nullable_string_owned(buf)? }; }
162        if flex {
163            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| {
164                Ok(false)
165            })?;
166        }
167        Ok(out)
168    }
169}
170
171/// Default JSON payload matching `Self::default()` for JVM oracle differential testing.
172/// Only includes fields valid for the given version.
173#[must_use]
174#[allow(unused_comparisons)]
175pub fn default_json(version: i16) -> ::serde_json::Value {
176    let mut obj = ::serde_json::Map::new();
177    obj.insert("resources".to_string(), ::serde_json::Value::Array(vec![]));
178    obj.insert("validateOnly".to_string(), ::serde_json::Value::Bool(false));
179    ::serde_json::Value::Object(obj)
180}
181
182impl crate::ProtocolRequest for AlterConfigsRequest {
183    const API_KEY: i16 = API_KEY;
184    const MIN_VERSION: i16 = MIN_VERSION;
185    const MAX_VERSION: i16 = MAX_VERSION;
186    const FLEXIBLE_MIN: i16 = FLEXIBLE_MIN;
187    type Response = super::alter_configs_response::AlterConfigsResponse;
188}