Skip to main content

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