Skip to main content

crabka_protocol/opt/rustwide/workdir/generated/
SyncGroupRequest.owned.rs

1// AUTO-GENERATED by crabka-protocol-codegen against a9ce3221537b8653448750697915607dc7936cf3. Do not edit.
2
3use crate::primitives::fixed::{get_i32, put_i32};
4use crate::primitives::string_bytes::{
5    bytes_len, compact_bytes_len, get_bytes_owned, get_compact_bytes_owned, put_bytes,
6    put_compact_bytes,
7};
8use crate::primitives::string_bytes::{
9    compact_nullable_string_len, compact_string_len, get_compact_nullable_string_owned,
10    get_compact_string_owned, get_nullable_string_owned, get_string_owned, nullable_string_len,
11    put_compact_nullable_string, put_compact_string, put_nullable_string, put_string, string_len,
12};
13use crate::tagged_fields::{WriteTaggedFields, read_tagged_fields, tagged_fields_len};
14use crate::{Decode, Encode, ProtocolError, UnknownTaggedFields};
15use bytes::{Buf, BufMut};
16pub const API_KEY: i16 = 14;
17pub const MIN_VERSION: i16 = 0;
18pub const MAX_VERSION: i16 = 5;
19pub const FLEXIBLE_MIN: i16 = 4;
20#[inline]
21fn is_flexible(version: i16) -> bool {
22    version >= FLEXIBLE_MIN
23}
24#[derive(Debug, Clone, PartialEq, Eq, Default)]
25pub struct SyncGroupRequest {
26    pub group_id: String,
27    pub generation_id: i32,
28    pub member_id: String,
29    pub group_instance_id: Option<String>,
30    pub protocol_type: Option<String>,
31    pub protocol_name: Option<String>,
32    pub assignments: Vec<SyncGroupRequestAssignment>,
33    pub unknown_tagged_fields: UnknownTaggedFields,
34}
35impl Encode for SyncGroupRequest {
36    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
37        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
38            return Err(ProtocolError::UnsupportedVersion {
39                api_key: API_KEY,
40                version,
41            });
42        }
43        let flex = is_flexible(version);
44        if version >= 0 {
45            if flex {
46                put_compact_string(buf, &self.group_id);
47            } else {
48                put_string(buf, &self.group_id);
49            }
50        }
51        if version >= 0 {
52            put_i32(buf, self.generation_id);
53        }
54        if version >= 0 {
55            if flex {
56                put_compact_string(buf, &self.member_id);
57            } else {
58                put_string(buf, &self.member_id);
59            }
60        }
61        if version >= 3 {
62            if flex {
63                put_compact_nullable_string(buf, self.group_instance_id.as_deref());
64            } else {
65                put_nullable_string(buf, self.group_instance_id.as_deref());
66            }
67        }
68        if version >= 5 {
69            if flex {
70                put_compact_nullable_string(buf, self.protocol_type.as_deref());
71            } else {
72                put_nullable_string(buf, self.protocol_type.as_deref());
73            }
74        }
75        if version >= 5 {
76            if flex {
77                put_compact_nullable_string(buf, self.protocol_name.as_deref());
78            } else {
79                put_nullable_string(buf, self.protocol_name.as_deref());
80            }
81        }
82        if version >= 0 {
83            {
84                crate::primitives::array::put_array_len(buf, (self.assignments).len(), flex);
85                for it in &self.assignments {
86                    it.encode(buf, version)?;
87                }
88            }
89        }
90        if flex {
91            let tagged = WriteTaggedFields::new();
92            tagged.write(buf, &self.unknown_tagged_fields);
93        }
94        Ok(())
95    }
96    fn encoded_len(&self, version: i16) -> usize {
97        let flex = is_flexible(version);
98        let mut n: usize = 0;
99        if version >= 0 {
100            n += if flex {
101                compact_string_len(&self.group_id)
102            } else {
103                string_len(&self.group_id)
104            };
105        }
106        if version >= 0 {
107            n += 4;
108        }
109        if version >= 0 {
110            n += if flex {
111                compact_string_len(&self.member_id)
112            } else {
113                string_len(&self.member_id)
114            };
115        }
116        if version >= 3 {
117            n += if flex {
118                compact_nullable_string_len(self.group_instance_id.as_deref())
119            } else {
120                nullable_string_len(self.group_instance_id.as_deref())
121            };
122        }
123        if version >= 5 {
124            n += if flex {
125                compact_nullable_string_len(self.protocol_type.as_deref())
126            } else {
127                nullable_string_len(self.protocol_type.as_deref())
128            };
129        }
130        if version >= 5 {
131            n += if flex {
132                compact_nullable_string_len(self.protocol_name.as_deref())
133            } else {
134                nullable_string_len(self.protocol_name.as_deref())
135            };
136        }
137        if version >= 0 {
138            n += {
139                let prefix =
140                    crate::primitives::array::array_len_prefix_len((self.assignments).len(), flex);
141                let body: usize = (self.assignments)
142                    .iter()
143                    .map(|it| it.encoded_len(version))
144                    .sum();
145                prefix + body
146            };
147        }
148        if flex {
149            let known_pairs: Vec<(u32, usize)> = Vec::new();
150            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
151        }
152        n
153    }
154}
155impl Decode<'_> for SyncGroupRequest {
156    fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
157        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
158            return Err(ProtocolError::UnsupportedVersion {
159                api_key: API_KEY,
160                version,
161            });
162        }
163        let flex = is_flexible(version);
164        let mut out = Self::default();
165        if version >= 0 {
166            out.group_id = if flex {
167                get_compact_string_owned(buf)?
168            } else {
169                get_string_owned(buf)?
170            };
171        }
172        if version >= 0 {
173            out.generation_id = get_i32(buf)?;
174        }
175        if version >= 0 {
176            out.member_id = if flex {
177                get_compact_string_owned(buf)?
178            } else {
179                get_string_owned(buf)?
180            };
181        }
182        if version >= 3 {
183            out.group_instance_id = if flex {
184                get_compact_nullable_string_owned(buf)?
185            } else {
186                get_nullable_string_owned(buf)?
187            };
188        }
189        if version >= 5 {
190            out.protocol_type = if flex {
191                get_compact_nullable_string_owned(buf)?
192            } else {
193                get_nullable_string_owned(buf)?
194            };
195        }
196        if version >= 5 {
197            out.protocol_name = if flex {
198                get_compact_nullable_string_owned(buf)?
199            } else {
200                get_nullable_string_owned(buf)?
201            };
202        }
203        if version >= 0 {
204            out.assignments = {
205                let n = crate::primitives::array::get_array_len(buf, flex)?;
206                let mut v = Vec::with_capacity(n);
207                for _ in 0..n {
208                    v.push(SyncGroupRequestAssignment::decode(buf, version)?);
209                }
210                v
211            };
212        }
213        if flex {
214            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
215        }
216        Ok(out)
217    }
218}
219#[cfg(test)]
220impl SyncGroupRequest {
221    #[must_use]
222    pub fn populated(version: i16) -> Self {
223        let mut m = Self::default();
224        if version >= 0 {
225            m.group_id = "x".to_string();
226        }
227        if version >= 0 {
228            m.generation_id = 1i32;
229        }
230        if version >= 0 {
231            m.member_id = "x".to_string();
232        }
233        if version >= 3 {
234            m.group_instance_id = Some("x".to_string());
235        }
236        if version >= 5 {
237            m.protocol_type = Some("x".to_string());
238        }
239        if version >= 5 {
240            m.protocol_name = Some("x".to_string());
241        }
242        if version >= 0 {
243            m.assignments = vec![SyncGroupRequestAssignment::populated(version)];
244        }
245        m
246    }
247}
248#[derive(Debug, Clone, PartialEq, Eq, Default)]
249pub struct SyncGroupRequestAssignment {
250    pub member_id: String,
251    pub assignment: ::bytes::Bytes,
252    pub unknown_tagged_fields: UnknownTaggedFields,
253}
254impl Encode for SyncGroupRequestAssignment {
255    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
256        let flex = version >= 4;
257        if version >= 0 {
258            if flex {
259                put_compact_string(buf, &self.member_id);
260            } else {
261                put_string(buf, &self.member_id);
262            }
263        }
264        if version >= 0 {
265            if flex {
266                put_compact_bytes(buf, &self.assignment);
267            } else {
268                put_bytes(buf, &self.assignment);
269            }
270        }
271        if flex {
272            let tagged = WriteTaggedFields::new();
273            tagged.write(buf, &self.unknown_tagged_fields);
274        }
275        Ok(())
276    }
277    fn encoded_len(&self, version: i16) -> usize {
278        let flex = version >= 4;
279        let mut n: usize = 0;
280        if version >= 0 {
281            n += if flex {
282                compact_string_len(&self.member_id)
283            } else {
284                string_len(&self.member_id)
285            };
286        }
287        if version >= 0 {
288            n += if flex {
289                compact_bytes_len(&self.assignment)
290            } else {
291                bytes_len(&self.assignment)
292            };
293        }
294        if flex {
295            let known_pairs: Vec<(u32, usize)> = Vec::new();
296            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
297        }
298        n
299    }
300}
301impl Decode<'_> for SyncGroupRequestAssignment {
302    fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
303        let flex = version >= 4;
304        let mut out = Self::default();
305        if version >= 0 {
306            out.member_id = if flex {
307                get_compact_string_owned(buf)?
308            } else {
309                get_string_owned(buf)?
310            };
311        }
312        if version >= 0 {
313            out.assignment = if flex {
314                get_compact_bytes_owned(buf)?
315            } else {
316                get_bytes_owned(buf)?
317            };
318        }
319        if flex {
320            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
321        }
322        Ok(out)
323    }
324}
325#[cfg(test)]
326impl SyncGroupRequestAssignment {
327    #[must_use]
328    pub fn populated(version: i16) -> Self {
329        let mut m = Self::default();
330        if version >= 0 {
331            m.member_id = "x".to_string();
332        }
333        if version >= 0 {
334            m.assignment = ::bytes::Bytes::from_static(b"x");
335        }
336        m
337    }
338}
339/// Default JSON payload matching `Self::default()` for JVM oracle differential testing.
340/// Only includes fields valid for the given version.
341#[must_use]
342#[allow(unused_comparisons)]
343pub fn default_json(version: i16) -> ::serde_json::Value {
344    let mut obj = ::serde_json::Map::new();
345    obj.insert(
346        "groupId".to_string(),
347        ::serde_json::Value::String(String::new()),
348    );
349    obj.insert("generationId".to_string(), ::serde_json::json!(0));
350    obj.insert(
351        "memberId".to_string(),
352        ::serde_json::Value::String(String::new()),
353    );
354    if version >= 3 {
355        obj.insert("groupInstanceId".to_string(), ::serde_json::Value::Null);
356    }
357    if version >= 5 {
358        obj.insert("protocolType".to_string(), ::serde_json::Value::Null);
359    }
360    if version >= 5 {
361        obj.insert("protocolName".to_string(), ::serde_json::Value::Null);
362    }
363    obj.insert(
364        "assignments".to_string(),
365        ::serde_json::Value::Array(vec![]),
366    );
367    ::serde_json::Value::Object(obj)
368}
369impl crate::ProtocolRequest for SyncGroupRequest {
370    const API_KEY: i16 = API_KEY;
371    const MIN_VERSION: i16 = MIN_VERSION;
372    const MAX_VERSION: i16 = MAX_VERSION;
373    const FLEXIBLE_MIN: i16 = FLEXIBLE_MIN;
374    type Response = super::sync_group_response::SyncGroupResponse;
375}