Skip to main content

crabka_protocol/opt/rustwide/workdir/generated/
DeleteTopicsResponse.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, put_i16, put_i32};
6use crate::primitives::string_bytes::{
7    compact_nullable_string_len, compact_string_len, nullable_string_len,
8    put_compact_nullable_string, put_compact_string, put_nullable_string, put_string,
9    string_len,
10};
11use crate::primitives::string_bytes_borrowed::{
12    get_compact_nullable_string_borrowed, get_compact_string_borrowed,
13    get_nullable_string_borrowed, get_string_borrowed,
14};
15use crate::tagged_fields::{read_tagged_fields, tagged_fields_len, WriteTaggedFields};
16use crate::{DecodeBorrow, Encode, ProtocolError, UnknownTaggedFields};
17
18pub const API_KEY: i16 = 20;
19pub const MIN_VERSION: i16 = 1;
20pub const MAX_VERSION: i16 = 6;
21pub const FLEXIBLE_MIN: i16 = 4;
22
23#[inline]
24fn is_flexible(version: i16) -> bool { version >= FLEXIBLE_MIN }
25
26#[derive(Debug, Clone, PartialEq, Eq)]
27pub struct DeleteTopicsResponse<'a> {
28    pub throttle_time_ms: i32,
29    pub responses: Vec<DeletableTopicResult<'a>>,
30    pub unknown_tagged_fields: UnknownTaggedFields,
31}
32
33impl<'a> Default for DeleteTopicsResponse<'a> {
34    fn default() -> Self {
35        Self {
36            throttle_time_ms: 0i32,
37            responses: Vec::new(),
38            unknown_tagged_fields: Default::default(),
39        }
40    }
41}
42
43impl<'a> DeleteTopicsResponse<'a> {
44    pub fn to_owned(&self) -> crate::owned::delete_topics_response::DeleteTopicsResponse {
45        crate::owned::delete_topics_response::DeleteTopicsResponse {
46            throttle_time_ms: (self.throttle_time_ms),
47            responses: (self.responses).iter().map(|it| it.to_owned()).collect(),
48            unknown_tagged_fields: self.unknown_tagged_fields.clone(),
49        }
50    }
51}
52
53impl<'a> Encode for DeleteTopicsResponse<'a> {
54    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
55        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
56            return Err(ProtocolError::UnsupportedVersion { api_key: API_KEY, version });
57        }
58        let flex = is_flexible(version);
59        if version >= 1 { put_i32(buf, self.throttle_time_ms) }
60        if version >= 0 { { crate::primitives::array::put_array_len(buf, (self.responses).len(), flex); for it in &self.responses { it.encode(buf, version)?; } } }
61        if flex {
62            let tagged = WriteTaggedFields::new();
63            tagged.write(buf, &self.unknown_tagged_fields);
64        }
65        Ok(())
66    }
67    fn encoded_len(&self, version: i16) -> usize {
68        let flex = is_flexible(version);
69        let mut n: usize = 0;
70        if version >= 1 { n += 4; }
71        if version >= 0 { n += { let prefix = crate::primitives::array::array_len_prefix_len((self.responses).len(), flex); let body: usize = (self.responses).iter().map(|it| it.encoded_len(version)).sum(); prefix + body }; }
72        if flex {
73            let known_pairs: Vec<(u32, usize)> = Vec::new();
74            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
75        }
76        n
77    }
78}
79
80impl<'de> DecodeBorrow<'de> for DeleteTopicsResponse<'de> {
81    fn decode_borrow(buf: &mut &'de [u8], version: i16) -> Result<Self, ProtocolError> {
82        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
83            return Err(ProtocolError::UnsupportedVersion { api_key: API_KEY, version });
84        }
85        let flex = is_flexible(version);
86        let mut out = Self::default();
87        if version >= 1 { out.throttle_time_ms = get_i32(buf)?; }
88        if version >= 0 { out.responses = { let n = crate::primitives::array::get_array_len(buf, flex)?; let mut v = Vec::with_capacity(n); for _ in 0..n { v.push(DeletableTopicResult::decode_borrow(buf, version)?); } v }; }
89        if flex {
90            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| {
91                Ok(false)
92            })?;
93        }
94        Ok(out)
95    }
96}
97
98#[derive(Debug, Clone, PartialEq, Eq)]
99pub struct DeletableTopicResult<'a> {
100    pub name: Option<&'a str>,
101    pub topic_id: crate::primitives::uuid::Uuid,
102    pub error_code: i16,
103    pub error_message: Option<&'a str>,
104    pub unknown_tagged_fields: UnknownTaggedFields,
105}
106
107impl<'a> Default for DeletableTopicResult<'a> {
108    fn default() -> Self {
109        Self {
110            name: None,
111            topic_id: Default::default(),
112            error_code: 0i16,
113            error_message: None,
114            unknown_tagged_fields: Default::default(),
115        }
116    }
117}
118
119impl<'a> DeletableTopicResult<'a> {
120    pub fn to_owned(&self) -> crate::owned::delete_topics_response::DeletableTopicResult {
121        crate::owned::delete_topics_response::DeletableTopicResult {
122            name: (self.name).map(|s| s.to_string()),
123            topic_id: (self.topic_id),
124            error_code: (self.error_code),
125            error_message: (self.error_message).map(|s| s.to_string()),
126            unknown_tagged_fields: self.unknown_tagged_fields.clone(),
127        }
128    }
129}
130
131impl<'a> Encode for DeletableTopicResult<'a> {
132    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
133        let flex = version >= 4;
134        if version >= 0 { if version >= 6 { if flex { put_compact_nullable_string(buf, self.name) } else { put_nullable_string(buf, self.name) } } else { if flex { put_compact_string(buf, (self.name).unwrap_or("")) } else { put_string(buf, (self.name).unwrap_or("")) } } }
135        if version >= 6 { crate::primitives::uuid::put_uuid(buf, self.topic_id) }
136        if version >= 0 { put_i16(buf, self.error_code) }
137        if version >= 5 { if flex { put_compact_nullable_string(buf, self.error_message) } else { put_nullable_string(buf, self.error_message) } }
138        if flex {
139            let tagged = WriteTaggedFields::new();
140            tagged.write(buf, &self.unknown_tagged_fields);
141        }
142        Ok(())
143    }
144    fn encoded_len(&self, version: i16) -> usize {
145        let flex = version >= 4;
146        let mut n: usize = 0;
147        if version >= 0 { n += if version >= 6 { if flex { compact_nullable_string_len(self.name) } else { nullable_string_len(self.name) } } else { if flex { compact_string_len((self.name).unwrap_or("")) } else { string_len((self.name).unwrap_or("")) } }; }
148        if version >= 6 { n += 16; }
149        if version >= 0 { n += 2; }
150        if version >= 5 { n += if flex { compact_nullable_string_len(self.error_message) } else { nullable_string_len(self.error_message) }; }
151        if flex {
152            let known_pairs: Vec<(u32, usize)> = Vec::new();
153            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
154        }
155        n
156    }
157}
158
159impl<'de> DecodeBorrow<'de> for DeletableTopicResult<'de> {
160    fn decode_borrow(buf: &mut &'de [u8], version: i16) -> Result<Self, ProtocolError> {
161        let flex = version >= 4;
162        let mut out = Self::default();
163        if version >= 0 { out.name = if version >= 6 { if flex { get_compact_nullable_string_borrowed(buf)? } else { get_nullable_string_borrowed(buf)? } } else { Some(if flex { get_compact_string_borrowed(buf)? } else { get_string_borrowed(buf)? }) }; }
164        if version >= 6 { out.topic_id = crate::primitives::uuid::get_uuid(buf)?; }
165        if version >= 0 { out.error_code = get_i16(buf)?; }
166        if version >= 5 { out.error_message = if flex { get_compact_nullable_string_borrowed(buf)? } else { get_nullable_string_borrowed(buf)? }; }
167        if flex {
168            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| {
169                Ok(false)
170            })?;
171        }
172        Ok(out)
173    }
174}