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