Skip to main content

krabka_protocol/opt/rustwide/workdir/generated/
AllocateProducerIdsResponse.borrowed.rs

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