Skip to main content

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

1// AUTO-GENERATED by crabka-protocol-codegen against a9ce3221537b8653448750697915607dc7936cf3. Do not edit.
2use crate::primitives::fixed::{get_i32, get_i64, 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)]
15pub struct AllocateProducerIdsRequest {
16    pub broker_id: i32,
17    pub broker_epoch: i64,
18    pub unknown_tagged_fields: UnknownTaggedFields,
19}
20impl Default for AllocateProducerIdsRequest {
21    fn default() -> Self {
22        Self {
23            broker_id: 0i32,
24            broker_epoch: -1i64,
25            unknown_tagged_fields: Default::default(),
26        }
27    }
28}
29impl AllocateProducerIdsRequest {
30    pub fn to_owned(
31        &self,
32    ) -> crate::owned::allocate_producer_ids_request::AllocateProducerIdsRequest {
33        crate::owned::allocate_producer_ids_request::AllocateProducerIdsRequest {
34            broker_id: (self.broker_id),
35            broker_epoch: (self.broker_epoch),
36            unknown_tagged_fields: self.unknown_tagged_fields.clone(),
37        }
38    }
39}
40impl Encode for AllocateProducerIdsRequest {
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.broker_id);
51        }
52        if version >= 0 {
53            put_i64(buf, self.broker_epoch);
54        }
55        if flex {
56            let tagged = WriteTaggedFields::new();
57            tagged.write(buf, &self.unknown_tagged_fields);
58        }
59        Ok(())
60    }
61    fn encoded_len(&self, version: i16) -> usize {
62        let flex = is_flexible(version);
63        let mut n: usize = 0;
64        if version >= 0 {
65            n += 4;
66        }
67        if version >= 0 {
68            n += 8;
69        }
70        if flex {
71            let known_pairs: Vec<(u32, usize)> = Vec::new();
72            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
73        }
74        n
75    }
76}
77impl<'de> DecodeBorrow<'de> for AllocateProducerIdsRequest {
78    fn decode_borrow(buf: &mut &'de [u8], version: i16) -> Result<Self, ProtocolError> {
79        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
80            return Err(ProtocolError::UnsupportedVersion {
81                api_key: API_KEY,
82                version,
83            });
84        }
85        let flex = is_flexible(version);
86        let mut out = Self::default();
87        if version >= 0 {
88            out.broker_id = get_i32(buf)?;
89        }
90        if version >= 0 {
91            out.broker_epoch = get_i64(buf)?;
92        }
93        if flex {
94            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
95        }
96        Ok(out)
97    }
98}
99#[cfg(test)]
100impl AllocateProducerIdsRequest {
101    #[must_use]
102    pub fn populated(version: i16) -> Self {
103        let mut m = Self::default();
104        if version >= 0 {
105            m.broker_id = 1i32;
106        }
107        if version >= 0 {
108            m.broker_epoch = 1i64;
109        }
110        m
111    }
112}