Skip to main content

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