crabka_protocol/opt/rustwide/workdir/generated/
WriteShareGroupStateResponse.borrowed.rs1use 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 = 85;
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 WriteShareGroupStateResponse<'a> {
28 pub results: Vec<WriteStateResult<'a>>,
29 pub unknown_tagged_fields: UnknownTaggedFields,
30}
31
32impl<'a> Default for WriteShareGroupStateResponse<'a> {
33 fn default() -> Self {
34 Self {
35 results: Vec::new(),
36 unknown_tagged_fields: Default::default(),
37 }
38 }
39}
40
41impl<'a> WriteShareGroupStateResponse<'a> {
42 pub fn to_owned(&self) -> crate::owned::write_share_group_state_response::WriteShareGroupStateResponse {
43 crate::owned::write_share_group_state_response::WriteShareGroupStateResponse {
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 WriteShareGroupStateResponse<'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 WriteShareGroupStateResponse<'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(WriteStateResult::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 WriteStateResult<'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 WriteStateResult<'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> WriteStateResult<'a> {
110 pub fn to_owned(&self) -> crate::owned::write_share_group_state_response::WriteStateResult {
111 crate::owned::write_share_group_state_response::WriteStateResult {
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 WriteStateResult<'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 WriteStateResult<'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 unknown_tagged_fields: UnknownTaggedFields,
164}
165
166impl<'a> Default for PartitionResult<'a> {
167 fn default() -> Self {
168 Self {
169 partition: 0i32,
170 error_code: 0i16,
171 error_message: None,
172 unknown_tagged_fields: Default::default(),
173 }
174 }
175}
176
177impl<'a> PartitionResult<'a> {
178 pub fn to_owned(&self) -> crate::owned::write_share_group_state_response::PartitionResult {
179 crate::owned::write_share_group_state_response::PartitionResult {
180 partition: (self.partition),
181 error_code: (self.error_code),
182 error_message: (self.error_message).map(|s| s.to_string()),
183 unknown_tagged_fields: self.unknown_tagged_fields.clone(),
184 }
185 }
186}
187
188impl<'a> Encode for PartitionResult<'a> {
189 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
190 let flex = version >= 0;
191 if version >= 0 { put_i32(buf, self.partition) }
192 if version >= 0 { put_i16(buf, self.error_code) }
193 if version >= 0 { if flex { put_compact_nullable_string(buf, self.error_message) } else { put_nullable_string(buf, self.error_message) } }
194 if flex {
195 let tagged = WriteTaggedFields::new();
196 tagged.write(buf, &self.unknown_tagged_fields);
197 }
198 Ok(())
199 }
200 fn encoded_len(&self, version: i16) -> usize {
201 let flex = version >= 0;
202 let mut n: usize = 0;
203 if version >= 0 { n += 4; }
204 if version >= 0 { n += 2; }
205 if version >= 0 { n += if flex { compact_nullable_string_len(self.error_message) } else { nullable_string_len(self.error_message) }; }
206 if flex {
207 let known_pairs: Vec<(u32, usize)> = Vec::new();
208 n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
209 }
210 n
211 }
212}
213
214impl<'de> DecodeBorrow<'de> for PartitionResult<'de> {
215 fn decode_borrow(buf: &mut &'de [u8], version: i16) -> Result<Self, ProtocolError> {
216 let flex = version >= 0;
217 let mut out = Self::default();
218 if version >= 0 { out.partition = get_i32(buf)?; }
219 if version >= 0 { out.error_code = get_i16(buf)?; }
220 if version >= 0 { out.error_message = if flex { get_compact_nullable_string_borrowed(buf)? } else { get_nullable_string_borrowed(buf)? }; }
221 if flex {
222 out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| {
223 Ok(false)
224 })?;
225 }
226 Ok(out)
227 }
228}