Skip to main content

crabka_protocol/opt/rustwide/workdir/generated/
InitProducerIdResponse.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 = 22;
7pub const MIN_VERSION: i16 = 0;
8pub const MAX_VERSION: i16 = 6;
9pub const FLEXIBLE_MIN: i16 = 2;
10#[inline]
11fn is_flexible(version: i16) -> bool {
12    version >= FLEXIBLE_MIN
13}
14#[derive(Debug, Clone, PartialEq, Eq)]
15pub struct InitProducerIdResponse {
16    pub throttle_time_ms: i32,
17    pub error_code: i16,
18    pub producer_id: i64,
19    pub producer_epoch: i16,
20    pub ongoing_txn_producer_id: i64,
21    pub ongoing_txn_producer_epoch: i16,
22    pub unknown_tagged_fields: UnknownTaggedFields,
23}
24impl Default for InitProducerIdResponse {
25    fn default() -> Self {
26        Self {
27            throttle_time_ms: 0i32,
28            error_code: 0i16,
29            producer_id: -1i64,
30            producer_epoch: 0i16,
31            ongoing_txn_producer_id: -1i64,
32            ongoing_txn_producer_epoch: -1i16,
33            unknown_tagged_fields: Default::default(),
34        }
35    }
36}
37impl InitProducerIdResponse {
38    pub fn to_owned(&self) -> crate::owned::init_producer_id_response::InitProducerIdResponse {
39        crate::owned::init_producer_id_response::InitProducerIdResponse {
40            throttle_time_ms: (self.throttle_time_ms),
41            error_code: (self.error_code),
42            producer_id: (self.producer_id),
43            producer_epoch: (self.producer_epoch),
44            ongoing_txn_producer_id: (self.ongoing_txn_producer_id),
45            ongoing_txn_producer_epoch: (self.ongoing_txn_producer_epoch),
46            unknown_tagged_fields: self.unknown_tagged_fields.clone(),
47        }
48    }
49}
50impl Encode for InitProducerIdResponse {
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 {
54                api_key: API_KEY,
55                version,
56            });
57        }
58        let flex = is_flexible(version);
59        if version >= 0 {
60            put_i32(buf, self.throttle_time_ms);
61        }
62        if version >= 0 {
63            put_i16(buf, self.error_code);
64        }
65        if version >= 0 {
66            put_i64(buf, self.producer_id);
67        }
68        if version >= 0 {
69            put_i16(buf, self.producer_epoch);
70        }
71        if version >= 6 {
72            put_i64(buf, self.ongoing_txn_producer_id);
73        }
74        if version >= 6 {
75            put_i16(buf, self.ongoing_txn_producer_epoch);
76        }
77        if flex {
78            let tagged = WriteTaggedFields::new();
79            tagged.write(buf, &self.unknown_tagged_fields);
80        }
81        Ok(())
82    }
83    fn encoded_len(&self, version: i16) -> usize {
84        let flex = is_flexible(version);
85        let mut n: usize = 0;
86        if version >= 0 {
87            n += 4;
88        }
89        if version >= 0 {
90            n += 2;
91        }
92        if version >= 0 {
93            n += 8;
94        }
95        if version >= 0 {
96            n += 2;
97        }
98        if version >= 6 {
99            n += 8;
100        }
101        if version >= 6 {
102            n += 2;
103        }
104        if flex {
105            let known_pairs: Vec<(u32, usize)> = Vec::new();
106            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
107        }
108        n
109    }
110}
111impl<'de> DecodeBorrow<'de> for InitProducerIdResponse {
112    fn decode_borrow(buf: &mut &'de [u8], version: i16) -> Result<Self, ProtocolError> {
113        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
114            return Err(ProtocolError::UnsupportedVersion {
115                api_key: API_KEY,
116                version,
117            });
118        }
119        let flex = is_flexible(version);
120        let mut out = Self::default();
121        if version >= 0 {
122            out.throttle_time_ms = get_i32(buf)?;
123        }
124        if version >= 0 {
125            out.error_code = get_i16(buf)?;
126        }
127        if version >= 0 {
128            out.producer_id = get_i64(buf)?;
129        }
130        if version >= 0 {
131            out.producer_epoch = get_i16(buf)?;
132        }
133        if version >= 6 {
134            out.ongoing_txn_producer_id = get_i64(buf)?;
135        }
136        if version >= 6 {
137            out.ongoing_txn_producer_epoch = get_i16(buf)?;
138        }
139        if flex {
140            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
141        }
142        Ok(out)
143    }
144}
145#[cfg(test)]
146impl InitProducerIdResponse {
147    #[must_use]
148    pub fn populated(version: i16) -> Self {
149        let mut m = Self::default();
150        if version >= 0 {
151            m.throttle_time_ms = 1i32;
152        }
153        if version >= 0 {
154            m.error_code = 1i16;
155        }
156        if version >= 0 {
157            m.producer_id = 1i64;
158        }
159        if version >= 0 {
160            m.producer_epoch = 1i16;
161        }
162        if version >= 6 {
163            m.ongoing_txn_producer_id = 1i64;
164        }
165        if version >= 6 {
166            m.ongoing_txn_producer_epoch = 1i16;
167        }
168        m
169    }
170}