Skip to main content

crabka_protocol/opt/rustwide/workdir/generated/
ListOffsetsResponse.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, get_i64, put_i16, put_i32, put_i64};
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::tagged_fields::{read_tagged_fields, tagged_fields_len, WriteTaggedFields};
13use crate::{DecodeBorrow, Encode, ProtocolError, UnknownTaggedFields};
14
15pub const API_KEY: i16 = 2;
16pub const MIN_VERSION: i16 = 1;
17pub const MAX_VERSION: i16 = 11;
18pub const FLEXIBLE_MIN: i16 = 6;
19
20#[inline]
21fn is_flexible(version: i16) -> bool { version >= FLEXIBLE_MIN }
22
23#[derive(Debug, Clone, PartialEq, Eq)]
24pub struct ListOffsetsResponse<'a> {
25    pub throttle_time_ms: i32,
26    pub topics: Vec<ListOffsetsTopicResponse<'a>>,
27    pub unknown_tagged_fields: UnknownTaggedFields,
28}
29
30impl<'a> Default for ListOffsetsResponse<'a> {
31    fn default() -> Self {
32        Self {
33            throttle_time_ms: 0i32,
34            topics: Vec::new(),
35            unknown_tagged_fields: Default::default(),
36        }
37    }
38}
39
40impl<'a> ListOffsetsResponse<'a> {
41    pub fn to_owned(&self) -> crate::owned::list_offsets_response::ListOffsetsResponse {
42        crate::owned::list_offsets_response::ListOffsetsResponse {
43            throttle_time_ms: (self.throttle_time_ms),
44            topics: (self.topics).iter().map(|it| it.to_owned()).collect(),
45            unknown_tagged_fields: self.unknown_tagged_fields.clone(),
46        }
47    }
48}
49
50impl<'a> Encode for ListOffsetsResponse<'a> {
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 { api_key: API_KEY, version });
54        }
55        let flex = is_flexible(version);
56        if version >= 2 { put_i32(buf, self.throttle_time_ms) }
57        if version >= 0 { { crate::primitives::array::put_array_len(buf, (self.topics).len(), flex); for it in &self.topics { it.encode(buf, version)?; } } }
58        if flex {
59            let tagged = WriteTaggedFields::new();
60            tagged.write(buf, &self.unknown_tagged_fields);
61        }
62        Ok(())
63    }
64    fn encoded_len(&self, version: i16) -> usize {
65        let flex = is_flexible(version);
66        let mut n: usize = 0;
67        if version >= 2 { 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        if flex {
70            let known_pairs: Vec<(u32, usize)> = Vec::new();
71            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
72        }
73        n
74    }
75}
76
77impl<'de> DecodeBorrow<'de> for ListOffsetsResponse<'de> {
78    fn decode_borrow(buf: &mut &'de [u8], version: i16) -> Result<Self, ProtocolError> {
79        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
80            return Err(ProtocolError::UnsupportedVersion { api_key: API_KEY, version });
81        }
82        let flex = is_flexible(version);
83        let mut out = Self::default();
84        if version >= 2 { out.throttle_time_ms = get_i32(buf)?; }
85        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(ListOffsetsTopicResponse::decode_borrow(buf, version)?); } v }; }
86        if flex {
87            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| {
88                Ok(false)
89            })?;
90        }
91        Ok(out)
92    }
93}
94
95#[derive(Debug, Clone, PartialEq, Eq)]
96pub struct ListOffsetsTopicResponse<'a> {
97    pub name: &'a str,
98    pub partitions: Vec<ListOffsetsPartitionResponse>,
99    pub unknown_tagged_fields: UnknownTaggedFields,
100}
101
102impl<'a> Default for ListOffsetsTopicResponse<'a> {
103    fn default() -> Self {
104        Self {
105            name: "",
106            partitions: Vec::new(),
107            unknown_tagged_fields: Default::default(),
108        }
109    }
110}
111
112impl<'a> ListOffsetsTopicResponse<'a> {
113    pub fn to_owned(&self) -> crate::owned::list_offsets_response::ListOffsetsTopicResponse {
114        crate::owned::list_offsets_response::ListOffsetsTopicResponse {
115            name: (self.name).to_string(),
116            partitions: (self.partitions).iter().map(|it| it.to_owned()).collect(),
117            unknown_tagged_fields: self.unknown_tagged_fields.clone(),
118        }
119    }
120}
121
122impl<'a> Encode for ListOffsetsTopicResponse<'a> {
123    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
124        let flex = version >= 6;
125        if version >= 0 { if flex { put_compact_string(buf, self.name) } else { put_string(buf, self.name) } }
126        if version >= 0 { { crate::primitives::array::put_array_len(buf, (self.partitions).len(), flex); for it in &self.partitions { it.encode(buf, version)?; } } }
127        if flex {
128            let tagged = WriteTaggedFields::new();
129            tagged.write(buf, &self.unknown_tagged_fields);
130        }
131        Ok(())
132    }
133    fn encoded_len(&self, version: i16) -> usize {
134        let flex = version >= 6;
135        let mut n: usize = 0;
136        if version >= 0 { n += if flex { compact_string_len(self.name) } else { string_len(self.name) }; }
137        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 }; }
138        if flex {
139            let known_pairs: Vec<(u32, usize)> = Vec::new();
140            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
141        }
142        n
143    }
144}
145
146impl<'de> DecodeBorrow<'de> for ListOffsetsTopicResponse<'de> {
147    fn decode_borrow(buf: &mut &'de [u8], version: i16) -> Result<Self, ProtocolError> {
148        let flex = version >= 6;
149        let mut out = Self::default();
150        if version >= 0 { out.name = if flex { get_compact_string_borrowed(buf)? } else { get_string_borrowed(buf)? }; }
151        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(ListOffsetsPartitionResponse::decode_borrow(buf, version)?); } v }; }
152        if flex {
153            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| {
154                Ok(false)
155            })?;
156        }
157        Ok(out)
158    }
159}
160
161#[derive(Debug, Clone, PartialEq, Eq)]
162pub struct ListOffsetsPartitionResponse {
163    pub partition_index: i32,
164    pub error_code: i16,
165    pub timestamp: i64,
166    pub offset: i64,
167    pub leader_epoch: i32,
168    pub unknown_tagged_fields: UnknownTaggedFields,
169}
170
171impl Default for ListOffsetsPartitionResponse {
172    fn default() -> Self {
173        Self {
174            partition_index: 0i32,
175            error_code: 0i16,
176            timestamp: -1i64,
177            offset: -1i64,
178            leader_epoch: -1i32,
179            unknown_tagged_fields: Default::default(),
180        }
181    }
182}
183
184impl ListOffsetsPartitionResponse {
185    pub fn to_owned(&self) -> crate::owned::list_offsets_response::ListOffsetsPartitionResponse {
186        crate::owned::list_offsets_response::ListOffsetsPartitionResponse {
187            partition_index: (self.partition_index),
188            error_code: (self.error_code),
189            timestamp: (self.timestamp),
190            offset: (self.offset),
191            leader_epoch: (self.leader_epoch),
192            unknown_tagged_fields: self.unknown_tagged_fields.clone(),
193        }
194    }
195}
196
197impl Encode for ListOffsetsPartitionResponse {
198    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
199        let flex = version >= 6;
200        if version >= 0 { put_i32(buf, self.partition_index) }
201        if version >= 0 { put_i16(buf, self.error_code) }
202        if version >= 1 { put_i64(buf, self.timestamp) }
203        if version >= 1 { put_i64(buf, self.offset) }
204        if version >= 4 { put_i32(buf, self.leader_epoch) }
205        if flex {
206            let tagged = WriteTaggedFields::new();
207            tagged.write(buf, &self.unknown_tagged_fields);
208        }
209        Ok(())
210    }
211    fn encoded_len(&self, version: i16) -> usize {
212        let flex = version >= 6;
213        let mut n: usize = 0;
214        if version >= 0 { n += 4; }
215        if version >= 0 { n += 2; }
216        if version >= 1 { n += 8; }
217        if version >= 1 { n += 8; }
218        if version >= 4 { n += 4; }
219        if flex {
220            let known_pairs: Vec<(u32, usize)> = Vec::new();
221            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
222        }
223        n
224    }
225}
226
227impl<'de> DecodeBorrow<'de> for ListOffsetsPartitionResponse {
228    fn decode_borrow(buf: &mut &'de [u8], version: i16) -> Result<Self, ProtocolError> {
229        let flex = version >= 6;
230        let mut out = Self::default();
231        if version >= 0 { out.partition_index = get_i32(buf)?; }
232        if version >= 0 { out.error_code = get_i16(buf)?; }
233        if version >= 1 { out.timestamp = get_i64(buf)?; }
234        if version >= 1 { out.offset = get_i64(buf)?; }
235        if version >= 4 { out.leader_epoch = get_i32(buf)?; }
236        if flex {
237            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| {
238                Ok(false)
239            })?;
240        }
241        Ok(out)
242    }
243}