crabka_protocol/opt/rustwide/workdir/generated/
JoinGroupResponse.owned.rs1use bytes::{Buf, BufMut};
4
5use crate::primitives::fixed::{get_bool, get_i16, get_i32, put_bool, 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::primitives::string_bytes::{bytes_len, compact_bytes_len, get_bytes_owned, get_compact_bytes_owned, put_bytes, put_compact_bytes};
13use crate::tagged_fields::{read_tagged_fields, tagged_fields_len, WriteTaggedFields};
14use crate::{Decode, Encode, ProtocolError, UnknownTaggedFields};
15
16pub const API_KEY: i16 = 11;
17pub const MIN_VERSION: i16 = 0;
18pub const MAX_VERSION: i16 = 9;
19pub const FLEXIBLE_MIN: i16 = 6;
20
21#[inline]
22fn is_flexible(version: i16) -> bool { version >= FLEXIBLE_MIN }
23
24#[derive(Debug, Clone, PartialEq, Eq)]
25pub struct JoinGroupResponse {
26 pub throttle_time_ms: i32,
27 pub error_code: i16,
28 pub generation_id: i32,
29 pub protocol_type: Option<String>,
30 pub protocol_name: Option<String>,
31 pub leader: String,
32 pub skip_assignment: bool,
33 pub member_id: String,
34 pub members: Vec<JoinGroupResponseMember>,
35 pub unknown_tagged_fields: UnknownTaggedFields,
36}
37
38impl Default for JoinGroupResponse {
39 fn default() -> Self {
40 Self {
41 throttle_time_ms: 0i32,
42 error_code: 0i16,
43 generation_id: -1i32,
44 protocol_type: None,
45 protocol_name: None,
46 leader: String::new(),
47 skip_assignment: false,
48 member_id: String::new(),
49 members: Vec::new(),
50 unknown_tagged_fields: Default::default(),
51 }
52 }
53}
54
55impl Encode for JoinGroupResponse {
56 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
57 if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
58 return Err(ProtocolError::UnsupportedVersion { api_key: API_KEY, version });
59 }
60 let flex = is_flexible(version);
61 if version >= 2 { put_i32(buf, self.throttle_time_ms) }
62 if version >= 0 { put_i16(buf, self.error_code) }
63 if version >= 0 { put_i32(buf, self.generation_id) }
64 if version >= 7 { if flex { put_compact_nullable_string(buf, self.protocol_type.as_deref()) } else { put_nullable_string(buf, self.protocol_type.as_deref()) } }
65 if version >= 0 { if version >= 7 { if flex { put_compact_nullable_string(buf, self.protocol_name.as_deref()) } else { put_nullable_string(buf, self.protocol_name.as_deref()) } } else { if flex { put_compact_string(buf, (self.protocol_name).as_deref().unwrap_or("")) } else { put_string(buf, (self.protocol_name).as_deref().unwrap_or("")) } } }
66 if version >= 0 { if flex { put_compact_string(buf, &self.leader) } else { put_string(buf, &self.leader) } }
67 if version >= 9 { put_bool(buf, self.skip_assignment) }
68 if version >= 0 { if flex { put_compact_string(buf, &self.member_id) } else { put_string(buf, &self.member_id) } }
69 if version >= 0 { { crate::primitives::array::put_array_len(buf, (self.members).len(), flex); for it in &self.members { it.encode(buf, version)?; } } }
70 if flex {
71 let tagged = WriteTaggedFields::new();
72 tagged.write(buf, &self.unknown_tagged_fields);
73 }
74 Ok(())
75 }
76 fn encoded_len(&self, version: i16) -> usize {
77 let flex = is_flexible(version);
78 let mut n: usize = 0;
79 if version >= 2 { n += 4; }
80 if version >= 0 { n += 2; }
81 if version >= 0 { n += 4; }
82 if version >= 7 { n += if flex { compact_nullable_string_len(self.protocol_type.as_deref()) } else { nullable_string_len(self.protocol_type.as_deref()) }; }
83 if version >= 0 { n += if version >= 7 { if flex { compact_nullable_string_len(self.protocol_name.as_deref()) } else { nullable_string_len(self.protocol_name.as_deref()) } } else { if flex { compact_string_len((self.protocol_name).as_deref().unwrap_or("")) } else { string_len((self.protocol_name).as_deref().unwrap_or("")) } }; }
84 if version >= 0 { n += if flex { compact_string_len(&self.leader) } else { string_len(&self.leader) }; }
85 if version >= 9 { n += 1; }
86 if version >= 0 { n += if flex { compact_string_len(&self.member_id) } else { string_len(&self.member_id) }; }
87 if version >= 0 { 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 }; }
88 if flex {
89 let known_pairs: Vec<(u32, usize)> = Vec::new();
90 n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
91 }
92 n
93 }
94}
95
96impl<'de> Decode<'de> for JoinGroupResponse {
97 fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
98 if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
99 return Err(ProtocolError::UnsupportedVersion { api_key: API_KEY, version });
100 }
101 let flex = is_flexible(version);
102 let mut out = Self::default();
103 if version >= 2 { out.throttle_time_ms = get_i32(buf)?; }
104 if version >= 0 { out.error_code = get_i16(buf)?; }
105 if version >= 0 { out.generation_id = get_i32(buf)?; }
106 if version >= 7 { out.protocol_type = if flex { get_compact_nullable_string_owned(buf)? } else { get_nullable_string_owned(buf)? }; }
107 if version >= 0 { out.protocol_name = if version >= 7 { if flex { get_compact_nullable_string_owned(buf)? } else { get_nullable_string_owned(buf)? } } else { Some(if flex { get_compact_string_owned(buf)? } else { get_string_owned(buf)? }) }; }
108 if version >= 0 { out.leader = if flex { get_compact_string_owned(buf)? } else { get_string_owned(buf)? }; }
109 if version >= 9 { out.skip_assignment = get_bool(buf)?; }
110 if version >= 0 { out.member_id = if flex { get_compact_string_owned(buf)? } else { get_string_owned(buf)? }; }
111 if version >= 0 { 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(JoinGroupResponseMember::decode(buf, version)?); } v }; }
112 if flex {
113 out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| {
114 Ok(false)
115 })?;
116 }
117 Ok(out)
118 }
119}
120
121#[derive(Debug, Clone, PartialEq, Eq, Default)]
122pub struct JoinGroupResponseMember {
123 pub member_id: String,
124 pub group_instance_id: Option<String>,
125 pub metadata: ::bytes::Bytes,
126 pub unknown_tagged_fields: UnknownTaggedFields,
127}
128
129impl Encode for JoinGroupResponseMember {
130 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
131 let flex = version >= 6;
132 if version >= 0 { if flex { put_compact_string(buf, &self.member_id) } else { put_string(buf, &self.member_id) } }
133 if version >= 5 { if flex { put_compact_nullable_string(buf, self.group_instance_id.as_deref()) } else { put_nullable_string(buf, self.group_instance_id.as_deref()) } }
134 if version >= 0 { if flex { put_compact_bytes(buf, &self.metadata) } else { put_bytes(buf, &self.metadata) } }
135 if flex {
136 let tagged = WriteTaggedFields::new();
137 tagged.write(buf, &self.unknown_tagged_fields);
138 }
139 Ok(())
140 }
141 fn encoded_len(&self, version: i16) -> usize {
142 let flex = version >= 6;
143 let mut n: usize = 0;
144 if version >= 0 { n += if flex { compact_string_len(&self.member_id) } else { string_len(&self.member_id) }; }
145 if version >= 5 { n += if flex { compact_nullable_string_len(self.group_instance_id.as_deref()) } else { nullable_string_len(self.group_instance_id.as_deref()) }; }
146 if version >= 0 { n += if flex { compact_bytes_len(&self.metadata) } else { bytes_len(&self.metadata) }; }
147 if flex {
148 let known_pairs: Vec<(u32, usize)> = Vec::new();
149 n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
150 }
151 n
152 }
153}
154
155impl<'de> Decode<'de> for JoinGroupResponseMember {
156 fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
157 let flex = version >= 6;
158 let mut out = Self::default();
159 if version >= 0 { out.member_id = if flex { get_compact_string_owned(buf)? } else { get_string_owned(buf)? }; }
160 if version >= 5 { out.group_instance_id = if flex { get_compact_nullable_string_owned(buf)? } else { get_nullable_string_owned(buf)? }; }
161 if version >= 0 { out.metadata = if flex { get_compact_bytes_owned(buf)? } else { get_bytes_owned(buf)? }; }
162 if flex {
163 out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| {
164 Ok(false)
165 })?;
166 }
167 Ok(out)
168 }
169}
170
171#[must_use]
174#[allow(unused_comparisons)]
175pub fn default_json(version: i16) -> ::serde_json::Value {
176 let mut obj = ::serde_json::Map::new();
177 if version >= 2 {
178 obj.insert("throttleTimeMs".to_string(), ::serde_json::json!(0));
179 }
180 obj.insert("errorCode".to_string(), ::serde_json::json!(0));
181 obj.insert("generationId".to_string(), ::serde_json::json!(-1));
182 if version >= 7 {
183 obj.insert("protocolType".to_string(), ::serde_json::Value::Null);
184 }
185 obj.insert("protocolName".to_string(), if version >= 7 { ::serde_json::Value::Null } else { ::serde_json::Value::String(String::new()) });
186 obj.insert("leader".to_string(), ::serde_json::Value::String(String::new()));
187 if version >= 9 {
188 obj.insert("skipAssignment".to_string(), ::serde_json::Value::Bool(false));
189 }
190 obj.insert("memberId".to_string(), ::serde_json::Value::String(String::new()));
191 obj.insert("members".to_string(), ::serde_json::Value::Array(vec![]));
192 ::serde_json::Value::Object(obj)
193}