Skip to main content

krabka_protocol/opt/rustwide/workdir/generated/
AllocateProducerIdsResponse.borrowed.rs

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