Skip to main content

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

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