crabka_protocol/opt/rustwide/workdir/generated/
LeaveGroupResponse.owned.rs1use bytes::{Buf, 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, get_compact_nullable_string_owned,
8 get_compact_string_owned, get_nullable_string_owned, get_string_owned, nullable_string_len,
9 put_compact_nullable_string, put_compact_string, put_nullable_string, put_string,
10 string_len,
11};
12use crate::tagged_fields::{read_tagged_fields, tagged_fields_len, WriteTaggedFields};
13use crate::{Decode, Encode, ProtocolError, UnknownTaggedFields};
14
15pub const API_KEY: i16 = 13;
16pub const MIN_VERSION: i16 = 0;
17pub const MAX_VERSION: i16 = 5;
18pub const FLEXIBLE_MIN: i16 = 4;
19
20#[inline]
21fn is_flexible(version: i16) -> bool { version >= FLEXIBLE_MIN }
22
23#[derive(Debug, Clone, PartialEq, Eq, Default)]
24pub struct LeaveGroupResponse {
25 pub throttle_time_ms: i32,
26 pub error_code: i16,
27 pub members: Vec<MemberResponse>,
28 pub unknown_tagged_fields: UnknownTaggedFields,
29}
30
31impl Encode for LeaveGroupResponse {
32 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
33 if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
34 return Err(ProtocolError::UnsupportedVersion { api_key: API_KEY, version });
35 }
36 let flex = is_flexible(version);
37 if version >= 1 { put_i32(buf, self.throttle_time_ms) }
38 if version >= 0 { put_i16(buf, self.error_code) }
39 if version >= 3 { { crate::primitives::array::put_array_len(buf, (self.members).len(), flex); for it in &self.members { it.encode(buf, version)?; } } }
40 if flex {
41 let tagged = WriteTaggedFields::new();
42 tagged.write(buf, &self.unknown_tagged_fields);
43 }
44 Ok(())
45 }
46 fn encoded_len(&self, version: i16) -> usize {
47 let flex = is_flexible(version);
48 let mut n: usize = 0;
49 if version >= 1 { n += 4; }
50 if version >= 0 { n += 2; }
51 if version >= 3 { n += { let prefix = crate::primitives::array::array_len_prefix_len((self.members).len(), flex); let body: usize = (self.members).iter().map(|it| it.encoded_len(version)).sum(); prefix + body }; }
52 if flex {
53 let known_pairs: Vec<(u32, usize)> = Vec::new();
54 n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
55 }
56 n
57 }
58}
59
60impl<'de> Decode<'de> for LeaveGroupResponse {
61 fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
62 if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
63 return Err(ProtocolError::UnsupportedVersion { api_key: API_KEY, version });
64 }
65 let flex = is_flexible(version);
66 let mut out = Self::default();
67 if version >= 1 { out.throttle_time_ms = get_i32(buf)?; }
68 if version >= 0 { out.error_code = get_i16(buf)?; }
69 if version >= 3 { out.members = { let n = crate::primitives::array::get_array_len(buf, flex)?; let mut v = Vec::with_capacity(n); for _ in 0..n { v.push(MemberResponse::decode(buf, version)?); } v }; }
70 if flex {
71 out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| {
72 Ok(false)
73 })?;
74 }
75 Ok(out)
76 }
77}
78
79#[derive(Debug, Clone, PartialEq, Eq, Default)]
80pub struct MemberResponse {
81 pub member_id: String,
82 pub group_instance_id: Option<String>,
83 pub error_code: i16,
84 pub unknown_tagged_fields: UnknownTaggedFields,
85}
86
87impl Encode for MemberResponse {
88 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
89 let flex = version >= 4;
90 if version >= 3 { if flex { put_compact_string(buf, &self.member_id) } else { put_string(buf, &self.member_id) } }
91 if version >= 3 { if flex { put_compact_nullable_string(buf, self.group_instance_id.as_deref()) } else { put_nullable_string(buf, self.group_instance_id.as_deref()) } }
92 if version >= 3 { put_i16(buf, self.error_code) }
93 if flex {
94 let tagged = WriteTaggedFields::new();
95 tagged.write(buf, &self.unknown_tagged_fields);
96 }
97 Ok(())
98 }
99 fn encoded_len(&self, version: i16) -> usize {
100 let flex = version >= 4;
101 let mut n: usize = 0;
102 if version >= 3 { n += if flex { compact_string_len(&self.member_id) } else { string_len(&self.member_id) }; }
103 if version >= 3 { n += if flex { compact_nullable_string_len(self.group_instance_id.as_deref()) } else { nullable_string_len(self.group_instance_id.as_deref()) }; }
104 if version >= 3 { n += 2; }
105 if flex {
106 let known_pairs: Vec<(u32, usize)> = Vec::new();
107 n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
108 }
109 n
110 }
111}
112
113impl<'de> Decode<'de> for MemberResponse {
114 fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
115 let flex = version >= 4;
116 let mut out = Self::default();
117 if version >= 3 { out.member_id = if flex { get_compact_string_owned(buf)? } else { get_string_owned(buf)? }; }
118 if version >= 3 { out.group_instance_id = if flex { get_compact_nullable_string_owned(buf)? } else { get_nullable_string_owned(buf)? }; }
119 if version >= 3 { out.error_code = get_i16(buf)?; }
120 if flex {
121 out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| {
122 Ok(false)
123 })?;
124 }
125 Ok(out)
126 }
127}
128
129#[must_use]
132#[allow(unused_comparisons)]
133pub fn default_json(version: i16) -> ::serde_json::Value {
134 let mut obj = ::serde_json::Map::new();
135 if version >= 1 {
136 obj.insert("throttleTimeMs".to_string(), ::serde_json::json!(0));
137 }
138 obj.insert("errorCode".to_string(), ::serde_json::json!(0));
139 if version >= 3 {
140 obj.insert("members".to_string(), ::serde_json::Value::Array(vec![]));
141 }
142 ::serde_json::Value::Object(obj)
143}