Skip to main content

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

1// AUTO-GENERATED by crabka-protocol-codegen against a9ce3221537b8653448750697915607dc7936cf3. Do not edit.
2
3use bytes::BufMut;
4
5use crate::primitives::fixed::{get_i16, get_i32, get_i64, put_i16, put_i32, put_i64};
6use crate::tagged_fields::{WriteTaggedFields, read_tagged_fields, tagged_fields_len};
7use crate::{DecodeBorrow, Encode, ProtocolError, UnknownTaggedFields};
8
9pub const API_KEY: i16 = 62;
10pub const MIN_VERSION: i16 = 0;
11pub const MAX_VERSION: i16 = 4;
12pub const FLEXIBLE_MIN: i16 = 0;
13
14#[inline]
15fn is_flexible(version: i16) -> bool {
16    version >= FLEXIBLE_MIN
17}
18
19#[derive(Debug, Clone, PartialEq, Eq)]
20pub struct BrokerRegistrationResponse {
21    pub throttle_time_ms: i32,
22    pub error_code: i16,
23    pub broker_epoch: i64,
24    pub unknown_tagged_fields: UnknownTaggedFields,
25}
26impl Default for BrokerRegistrationResponse {
27    fn default() -> Self {
28        Self {
29            throttle_time_ms: 0i32,
30            error_code: 0i16,
31            broker_epoch: -1i64,
32            unknown_tagged_fields: Default::default(),
33        }
34    }
35}
36impl BrokerRegistrationResponse {
37    pub fn to_owned(
38        &self,
39    ) -> crate::owned::broker_registration_response::BrokerRegistrationResponse {
40        crate::owned::broker_registration_response::BrokerRegistrationResponse {
41            throttle_time_ms: (self.throttle_time_ms),
42            error_code: (self.error_code),
43            broker_epoch: (self.broker_epoch),
44            unknown_tagged_fields: self.unknown_tagged_fields.clone(),
45        }
46    }
47}
48impl Encode for BrokerRegistrationResponse {
49    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
50        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
51            return Err(ProtocolError::UnsupportedVersion {
52                api_key: API_KEY,
53                version,
54            });
55        }
56        let flex = is_flexible(version);
57        if version >= 0 {
58            put_i32(buf, self.throttle_time_ms);
59        }
60        if version >= 0 {
61            put_i16(buf, self.error_code);
62        }
63        if version >= 0 {
64            put_i64(buf, self.broker_epoch);
65        }
66        if flex {
67            let tagged = WriteTaggedFields::new();
68            tagged.write(buf, &self.unknown_tagged_fields);
69        }
70        Ok(())
71    }
72    fn encoded_len(&self, version: i16) -> usize {
73        let flex = is_flexible(version);
74        let mut n: usize = 0;
75        if version >= 0 {
76            n += 4;
77        }
78        if version >= 0 {
79            n += 2;
80        }
81        if version >= 0 {
82            n += 8;
83        }
84        if flex {
85            let known_pairs: Vec<(u32, usize)> = Vec::new();
86            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
87        }
88        n
89    }
90}
91impl<'de> DecodeBorrow<'de> for BrokerRegistrationResponse {
92    fn decode_borrow(buf: &mut &'de [u8], version: i16) -> Result<Self, ProtocolError> {
93        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
94            return Err(ProtocolError::UnsupportedVersion {
95                api_key: API_KEY,
96                version,
97            });
98        }
99        let flex = is_flexible(version);
100        let mut out = Self::default();
101        if version >= 0 {
102            out.throttle_time_ms = get_i32(buf)?;
103        }
104        if version >= 0 {
105            out.error_code = get_i16(buf)?;
106        }
107        if version >= 0 {
108            out.broker_epoch = get_i64(buf)?;
109        }
110        if flex {
111            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
112        }
113        Ok(out)
114    }
115}
116#[cfg(test)]
117impl BrokerRegistrationResponse {
118    #[must_use]
119    pub fn populated(version: i16) -> Self {
120        let mut m = Self::default();
121        if version >= 0 {
122            m.throttle_time_ms = 1i32;
123        }
124        if version >= 0 {
125            m.error_code = 1i16;
126        }
127        if version >= 0 {
128            m.broker_epoch = 1i64;
129        }
130        m
131    }
132}