Skip to main content

crabka_protocol/opt/rustwide/workdir/generated/
DescribeClusterResponse.borrowed.rs

1// AUTO-GENERATED by crabka-protocol-codegen against a9ce3221537b8653448750697915607dc7936cf3. Do not edit.
2
3use bytes::BufMut;
4
5use crate::primitives::fixed::{get_bool, get_i16, get_i32, get_i8, put_bool, put_i16, put_i32, put_i8};
6use crate::primitives::string_bytes::{
7    compact_nullable_string_len, compact_string_len, nullable_string_len,
8    put_compact_nullable_string, put_compact_string, put_nullable_string, put_string,
9    string_len,
10};
11use crate::primitives::string_bytes_borrowed::{
12    get_compact_nullable_string_borrowed, get_compact_string_borrowed,
13    get_nullable_string_borrowed, get_string_borrowed,
14};
15use crate::tagged_fields::{read_tagged_fields, tagged_fields_len, WriteTaggedFields};
16use crate::{DecodeBorrow, Encode, ProtocolError, UnknownTaggedFields};
17
18pub const API_KEY: i16 = 60;
19pub const MIN_VERSION: i16 = 0;
20pub const MAX_VERSION: i16 = 2;
21pub const FLEXIBLE_MIN: i16 = 0;
22
23#[inline]
24fn is_flexible(version: i16) -> bool { version >= FLEXIBLE_MIN }
25
26#[derive(Debug, Clone, PartialEq, Eq)]
27pub struct DescribeClusterResponse<'a> {
28    pub throttle_time_ms: i32,
29    pub error_code: i16,
30    pub error_message: Option<&'a str>,
31    pub endpoint_type: i8,
32    pub cluster_id: &'a str,
33    pub controller_id: i32,
34    pub brokers: Vec<DescribeClusterBroker<'a>>,
35    pub cluster_authorized_operations: i32,
36    pub unknown_tagged_fields: UnknownTaggedFields,
37}
38
39impl<'a> Default for DescribeClusterResponse<'a> {
40    fn default() -> Self {
41        Self {
42            throttle_time_ms: 0i32,
43            error_code: 0i16,
44            error_message: None,
45            endpoint_type: 1i8,
46            cluster_id: "",
47            controller_id: -1i32,
48            brokers: Vec::new(),
49            cluster_authorized_operations: -2_147_483_648i32,
50            unknown_tagged_fields: Default::default(),
51        }
52    }
53}
54
55impl<'a> DescribeClusterResponse<'a> {
56    pub fn to_owned(&self) -> crate::owned::describe_cluster_response::DescribeClusterResponse {
57        crate::owned::describe_cluster_response::DescribeClusterResponse {
58            throttle_time_ms: (self.throttle_time_ms),
59            error_code: (self.error_code),
60            error_message: (self.error_message).map(|s| s.to_string()),
61            endpoint_type: (self.endpoint_type),
62            cluster_id: (self.cluster_id).to_string(),
63            controller_id: (self.controller_id),
64            brokers: (self.brokers).iter().map(|it| it.to_owned()).collect(),
65            cluster_authorized_operations: (self.cluster_authorized_operations),
66            unknown_tagged_fields: self.unknown_tagged_fields.clone(),
67        }
68    }
69}
70
71impl<'a> Encode for DescribeClusterResponse<'a> {
72    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
73        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
74            return Err(ProtocolError::UnsupportedVersion { api_key: API_KEY, version });
75        }
76        let flex = is_flexible(version);
77        if version >= 0 { put_i32(buf, self.throttle_time_ms) }
78        if version >= 0 { put_i16(buf, self.error_code) }
79        if version >= 0 { if flex { put_compact_nullable_string(buf, self.error_message) } else { put_nullable_string(buf, self.error_message) } }
80        if version >= 1 { put_i8(buf, self.endpoint_type) }
81        if version >= 0 { if flex { put_compact_string(buf, self.cluster_id) } else { put_string(buf, self.cluster_id) } }
82        if version >= 0 { put_i32(buf, self.controller_id) }
83        if version >= 0 { { crate::primitives::array::put_array_len(buf, (self.brokers).len(), flex); for it in &self.brokers { it.encode(buf, version)?; } } }
84        if version >= 0 { put_i32(buf, self.cluster_authorized_operations) }
85        if flex {
86            let tagged = WriteTaggedFields::new();
87            tagged.write(buf, &self.unknown_tagged_fields);
88        }
89        Ok(())
90    }
91    fn encoded_len(&self, version: i16) -> usize {
92        let flex = is_flexible(version);
93        let mut n: usize = 0;
94        if version >= 0 { n += 4; }
95        if version >= 0 { n += 2; }
96        if version >= 0 { n += if flex { compact_nullable_string_len(self.error_message) } else { nullable_string_len(self.error_message) }; }
97        if version >= 1 { n += 1; }
98        if version >= 0 { n += if flex { compact_string_len(self.cluster_id) } else { string_len(self.cluster_id) }; }
99        if version >= 0 { n += 4; }
100        if version >= 0 { n += { let prefix = crate::primitives::array::array_len_prefix_len((self.brokers).len(), flex); let body: usize = (self.brokers).iter().map(|it| it.encoded_len(version)).sum(); prefix + body }; }
101        if version >= 0 { n += 4; }
102        if flex {
103            let known_pairs: Vec<(u32, usize)> = Vec::new();
104            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
105        }
106        n
107    }
108}
109
110impl<'de> DecodeBorrow<'de> for DescribeClusterResponse<'de> {
111    fn decode_borrow(buf: &mut &'de [u8], version: i16) -> Result<Self, ProtocolError> {
112        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
113            return Err(ProtocolError::UnsupportedVersion { api_key: API_KEY, version });
114        }
115        let flex = is_flexible(version);
116        let mut out = Self::default();
117        if version >= 0 { out.throttle_time_ms = get_i32(buf)?; }
118        if version >= 0 { out.error_code = get_i16(buf)?; }
119        if version >= 0 { out.error_message = if flex { get_compact_nullable_string_borrowed(buf)? } else { get_nullable_string_borrowed(buf)? }; }
120        if version >= 1 { out.endpoint_type = get_i8(buf)?; }
121        if version >= 0 { out.cluster_id = if flex { get_compact_string_borrowed(buf)? } else { get_string_borrowed(buf)? }; }
122        if version >= 0 { out.controller_id = get_i32(buf)?; }
123        if version >= 0 { out.brokers = { let n = crate::primitives::array::get_array_len(buf, flex)?; let mut v = Vec::with_capacity(n); for _ in 0..n { v.push(DescribeClusterBroker::decode_borrow(buf, version)?); } v }; }
124        if version >= 0 { out.cluster_authorized_operations = get_i32(buf)?; }
125        if flex {
126            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| {
127                Ok(false)
128            })?;
129        }
130        Ok(out)
131    }
132}
133
134#[derive(Debug, Clone, PartialEq, Eq)]
135pub struct DescribeClusterBroker<'a> {
136    pub broker_id: i32,
137    pub host: &'a str,
138    pub port: i32,
139    pub rack: Option<&'a str>,
140    pub is_fenced: bool,
141    pub unknown_tagged_fields: UnknownTaggedFields,
142}
143
144impl<'a> Default for DescribeClusterBroker<'a> {
145    fn default() -> Self {
146        Self {
147            broker_id: 0i32,
148            host: "",
149            port: 0i32,
150            rack: None,
151            is_fenced: false,
152            unknown_tagged_fields: Default::default(),
153        }
154    }
155}
156
157impl<'a> DescribeClusterBroker<'a> {
158    pub fn to_owned(&self) -> crate::owned::describe_cluster_response::DescribeClusterBroker {
159        crate::owned::describe_cluster_response::DescribeClusterBroker {
160            broker_id: (self.broker_id),
161            host: (self.host).to_string(),
162            port: (self.port),
163            rack: (self.rack).map(|s| s.to_string()),
164            is_fenced: (self.is_fenced),
165            unknown_tagged_fields: self.unknown_tagged_fields.clone(),
166        }
167    }
168}
169
170impl<'a> Encode for DescribeClusterBroker<'a> {
171    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
172        let flex = version >= 0;
173        if version >= 0 { put_i32(buf, self.broker_id) }
174        if version >= 0 { if flex { put_compact_string(buf, self.host) } else { put_string(buf, self.host) } }
175        if version >= 0 { put_i32(buf, self.port) }
176        if version >= 0 { if flex { put_compact_nullable_string(buf, self.rack) } else { put_nullable_string(buf, self.rack) } }
177        if version >= 2 { put_bool(buf, self.is_fenced) }
178        if flex {
179            let tagged = WriteTaggedFields::new();
180            tagged.write(buf, &self.unknown_tagged_fields);
181        }
182        Ok(())
183    }
184    fn encoded_len(&self, version: i16) -> usize {
185        let flex = version >= 0;
186        let mut n: usize = 0;
187        if version >= 0 { n += 4; }
188        if version >= 0 { n += if flex { compact_string_len(self.host) } else { string_len(self.host) }; }
189        if version >= 0 { n += 4; }
190        if version >= 0 { n += if flex { compact_nullable_string_len(self.rack) } else { nullable_string_len(self.rack) }; }
191        if version >= 2 { n += 1; }
192        if flex {
193            let known_pairs: Vec<(u32, usize)> = Vec::new();
194            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
195        }
196        n
197    }
198}
199
200impl<'de> DecodeBorrow<'de> for DescribeClusterBroker<'de> {
201    fn decode_borrow(buf: &mut &'de [u8], version: i16) -> Result<Self, ProtocolError> {
202        let flex = version >= 0;
203        let mut out = Self::default();
204        if version >= 0 { out.broker_id = get_i32(buf)?; }
205        if version >= 0 { out.host = if flex { get_compact_string_borrowed(buf)? } else { get_string_borrowed(buf)? }; }
206        if version >= 0 { out.port = get_i32(buf)?; }
207        if version >= 0 { out.rack = if flex { get_compact_nullable_string_borrowed(buf)? } else { get_nullable_string_borrowed(buf)? }; }
208        if version >= 2 { out.is_fenced = get_bool(buf)?; }
209        if flex {
210            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| {
211                Ok(false)
212            })?;
213        }
214        Ok(out)
215    }
216}