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::{read_tagged_fields, tagged_fields_len, WriteTaggedFields};
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 { version >= FLEXIBLE_MIN }
16
17#[derive(Debug, Clone, PartialEq, Eq)]
18pub struct AllocateProducerIdsResponse {
19    pub throttle_time_ms: i32,
20    pub error_code: i16,
21    pub producer_id_start: i64,
22    pub producer_id_len: i32,
23    pub unknown_tagged_fields: UnknownTaggedFields,
24}
25
26impl Default for AllocateProducerIdsResponse {
27    fn default() -> Self {
28        Self {
29            throttle_time_ms: 0i32,
30            error_code: 0i16,
31            producer_id_start: 0i64,
32            producer_id_len: 0i32,
33            unknown_tagged_fields: Default::default(),
34        }
35    }
36}
37
38impl AllocateProducerIdsResponse {
39    pub fn to_owned(&self) -> crate::owned::allocate_producer_ids_response::AllocateProducerIdsResponse {
40        crate::owned::allocate_producer_ids_response::AllocateProducerIdsResponse {
41            throttle_time_ms: (self.throttle_time_ms),
42            error_code: (self.error_code),
43            producer_id_start: (self.producer_id_start),
44            producer_id_len: (self.producer_id_len),
45            unknown_tagged_fields: self.unknown_tagged_fields.clone(),
46        }
47    }
48}
49
50impl Encode for AllocateProducerIdsResponse {
51    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
52        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
53            return Err(ProtocolError::UnsupportedVersion { api_key: API_KEY, version });
54        }
55        let flex = is_flexible(version);
56        if version >= 0 { put_i32(buf, self.throttle_time_ms) }
57        if version >= 0 { put_i16(buf, self.error_code) }
58        if version >= 0 { put_i64(buf, self.producer_id_start) }
59        if version >= 0 { put_i32(buf, self.producer_id_len) }
60        if flex {
61            let tagged = WriteTaggedFields::new();
62            tagged.write(buf, &self.unknown_tagged_fields);
63        }
64        Ok(())
65    }
66    fn encoded_len(&self, version: i16) -> usize {
67        let flex = is_flexible(version);
68        let mut n: usize = 0;
69        if version >= 0 { n += 4; }
70        if version >= 0 { n += 2; }
71        if version >= 0 { n += 8; }
72        if version >= 0 { n += 4; }
73        if flex {
74            let known_pairs: Vec<(u32, usize)> = Vec::new();
75            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
76        }
77        n
78    }
79}
80
81impl<'de> DecodeBorrow<'de> for AllocateProducerIdsResponse {
82    fn decode_borrow(buf: &mut &'de [u8], version: i16) -> Result<Self, ProtocolError> {
83        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
84            return Err(ProtocolError::UnsupportedVersion { api_key: API_KEY, version });
85        }
86        let flex = is_flexible(version);
87        let mut out = Self::default();
88        if version >= 0 { out.throttle_time_ms = get_i32(buf)?; }
89        if version >= 0 { out.error_code = get_i16(buf)?; }
90        if version >= 0 { out.producer_id_start = get_i64(buf)?; }
91        if version >= 0 { out.producer_id_len = get_i32(buf)?; }
92        if flex {
93            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| {
94                Ok(false)
95            })?;
96        }
97        Ok(out)
98    }
99}