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.
2
3use bytes::BufMut;
4
5use crate::primitives::fixed::{get_i32, get_i64, 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)]
20pub struct AllocateProducerIdsRequest {
21    pub broker_id: i32,
22    pub broker_epoch: i64,
23    pub unknown_tagged_fields: UnknownTaggedFields,
24}
25impl Default for AllocateProducerIdsRequest {
26    fn default() -> Self {
27        Self {
28            broker_id: 0i32,
29            broker_epoch: -1i64,
30            unknown_tagged_fields: Default::default(),
31        }
32    }
33}
34impl AllocateProducerIdsRequest {
35    pub fn to_owned(
36        &self,
37    ) -> crate::owned::allocate_producer_ids_request::AllocateProducerIdsRequest {
38        crate::owned::allocate_producer_ids_request::AllocateProducerIdsRequest {
39            broker_id: (self.broker_id),
40            broker_epoch: (self.broker_epoch),
41            unknown_tagged_fields: self.unknown_tagged_fields.clone(),
42        }
43    }
44}
45impl Encode for AllocateProducerIdsRequest {
46    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
47        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
48            return Err(ProtocolError::UnsupportedVersion {
49                api_key: API_KEY,
50                version,
51            });
52        }
53        let flex = is_flexible(version);
54        if version >= 0 {
55            put_i32(buf, self.broker_id);
56        }
57        if version >= 0 {
58            put_i64(buf, self.broker_epoch);
59        }
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 {
70            n += 4;
71        }
72        if version >= 0 {
73            n += 8;
74        }
75        if flex {
76            let known_pairs: Vec<(u32, usize)> = Vec::new();
77            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
78        }
79        n
80    }
81}
82impl<'de> DecodeBorrow<'de> for AllocateProducerIdsRequest {
83    fn decode_borrow(buf: &mut &'de [u8], version: i16) -> Result<Self, ProtocolError> {
84        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
85            return Err(ProtocolError::UnsupportedVersion {
86                api_key: API_KEY,
87                version,
88            });
89        }
90        let flex = is_flexible(version);
91        let mut out = Self::default();
92        if version >= 0 {
93            out.broker_id = get_i32(buf)?;
94        }
95        if version >= 0 {
96            out.broker_epoch = get_i64(buf)?;
97        }
98        if flex {
99            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
100        }
101        Ok(out)
102    }
103}
104#[cfg(test)]
105impl AllocateProducerIdsRequest {
106    #[must_use]
107    pub fn populated(version: i16) -> Self {
108        let mut m = Self::default();
109        if version >= 0 {
110            m.broker_id = 1i32;
111        }
112        if version >= 0 {
113            m.broker_epoch = 1i64;
114        }
115        m
116    }
117}