Skip to main content

crabka_protocol/opt/rustwide/workdir/generated/
AllocateProducerIdsResponse.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 = 67;
10pub const MIN_VERSION: i16 = 0;
11pub const MAX_VERSION: i16 = 0;
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, Default)]
20pub struct AllocateProducerIdsResponse {
21    pub throttle_time_ms: i32,
22    pub error_code: i16,
23    pub producer_id_start: i64,
24    pub producer_id_len: i32,
25    pub unknown_tagged_fields: UnknownTaggedFields,
26}
27impl AllocateProducerIdsResponse {
28    pub fn to_owned(
29        &self,
30    ) -> crate::owned::allocate_producer_ids_response::AllocateProducerIdsResponse {
31        crate::owned::allocate_producer_ids_response::AllocateProducerIdsResponse {
32            throttle_time_ms: (self.throttle_time_ms),
33            error_code: (self.error_code),
34            producer_id_start: (self.producer_id_start),
35            producer_id_len: (self.producer_id_len),
36            unknown_tagged_fields: self.unknown_tagged_fields.clone(),
37        }
38    }
39}
40impl Encode for AllocateProducerIdsResponse {
41    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
42        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
43            return Err(ProtocolError::UnsupportedVersion {
44                api_key: API_KEY,
45                version,
46            });
47        }
48        let flex = is_flexible(version);
49        if version >= 0 {
50            put_i32(buf, self.throttle_time_ms);
51        }
52        if version >= 0 {
53            put_i16(buf, self.error_code);
54        }
55        if version >= 0 {
56            put_i64(buf, self.producer_id_start);
57        }
58        if version >= 0 {
59            put_i32(buf, self.producer_id_len);
60        }
61        if flex {
62            let tagged = WriteTaggedFields::new();
63            tagged.write(buf, &self.unknown_tagged_fields);
64        }
65        Ok(())
66    }
67    fn encoded_len(&self, version: i16) -> usize {
68        let flex = is_flexible(version);
69        let mut n: usize = 0;
70        if version >= 0 {
71            n += 4;
72        }
73        if version >= 0 {
74            n += 2;
75        }
76        if version >= 0 {
77            n += 8;
78        }
79        if version >= 0 {
80            n += 4;
81        }
82        if flex {
83            let known_pairs: Vec<(u32, usize)> = Vec::new();
84            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
85        }
86        n
87    }
88}
89impl<'de> DecodeBorrow<'de> for AllocateProducerIdsResponse {
90    fn decode_borrow(buf: &mut &'de [u8], version: i16) -> Result<Self, ProtocolError> {
91        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
92            return Err(ProtocolError::UnsupportedVersion {
93                api_key: API_KEY,
94                version,
95            });
96        }
97        let flex = is_flexible(version);
98        let mut out = Self::default();
99        if version >= 0 {
100            out.throttle_time_ms = get_i32(buf)?;
101        }
102        if version >= 0 {
103            out.error_code = get_i16(buf)?;
104        }
105        if version >= 0 {
106            out.producer_id_start = get_i64(buf)?;
107        }
108        if version >= 0 {
109            out.producer_id_len = get_i32(buf)?;
110        }
111        if flex {
112            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
113        }
114        Ok(out)
115    }
116}
117#[cfg(test)]
118impl AllocateProducerIdsResponse {
119    #[must_use]
120    pub fn populated(version: i16) -> Self {
121        let mut m = Self::default();
122        if version >= 0 {
123            m.throttle_time_ms = 1i32;
124        }
125        if version >= 0 {
126            m.error_code = 1i16;
127        }
128        if version >= 0 {
129            m.producer_id_start = 1i64;
130        }
131        if version >= 0 {
132            m.producer_id_len = 1i32;
133        }
134        m
135    }
136}