crabka_protocol/opt/rustwide/workdir/generated/
StreamsGroupHeartbeatResponse.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 = 88;
16pub const MIN_VERSION: i16 = 0;
17pub const MAX_VERSION: i16 = 0;
18pub const FLEXIBLE_MIN: i16 = 0;
19
20#[inline]
21fn is_flexible(version: i16) -> bool { version >= FLEXIBLE_MIN }
22
23#[derive(Debug, Clone, PartialEq, Eq, Default)]
24pub struct StreamsGroupHeartbeatResponse {
25 pub throttle_time_ms: i32,
26 pub error_code: i16,
27 pub error_message: Option<String>,
28 pub member_id: String,
29 pub member_epoch: i32,
30 pub heartbeat_interval_ms: i32,
31 pub acceptable_recovery_lag: i32,
32 pub task_offset_interval_ms: i32,
33 pub status: Option<Vec<super::common::status::Status>>,
34 pub active_tasks: Option<Vec<super::common::task_ids::TaskIds>>,
35 pub standby_tasks: Option<Vec<super::common::task_ids::TaskIds>>,
36 pub warmup_tasks: Option<Vec<super::common::task_ids::TaskIds>>,
37 pub endpoint_information_epoch: i32,
38 pub partitions_by_user_endpoint: Option<Vec<EndpointToPartitions>>,
39 pub unknown_tagged_fields: UnknownTaggedFields,
40}
41
42impl Encode for StreamsGroupHeartbeatResponse {
43 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
44 if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
45 return Err(ProtocolError::UnsupportedVersion { api_key: API_KEY, version });
46 }
47 let flex = is_flexible(version);
48 if version >= 0 { put_i32(buf, self.throttle_time_ms) }
49 if version >= 0 { put_i16(buf, self.error_code) }
50 if version >= 0 { if flex { put_compact_nullable_string(buf, self.error_message.as_deref()) } else { put_nullable_string(buf, self.error_message.as_deref()) } }
51 if version >= 0 { if flex { put_compact_string(buf, &self.member_id) } else { put_string(buf, &self.member_id) } }
52 if version >= 0 { put_i32(buf, self.member_epoch) }
53 if version >= 0 { put_i32(buf, self.heartbeat_interval_ms) }
54 if version >= 0 { put_i32(buf, self.acceptable_recovery_lag) }
55 if version >= 0 { put_i32(buf, self.task_offset_interval_ms) }
56 if version >= 0 { { let len = (self.status).as_ref().map(Vec::len); crate::primitives::array::put_nullable_array_len(buf, len, flex); if let Some(v) = &self.status { for it in v { it.encode(buf, version)?; } } } }
57 if version >= 0 { { let len = (self.active_tasks).as_ref().map(Vec::len); crate::primitives::array::put_nullable_array_len(buf, len, flex); if let Some(v) = &self.active_tasks { for it in v { it.encode(buf, version)?; } } } }
58 if version >= 0 { { let len = (self.standby_tasks).as_ref().map(Vec::len); crate::primitives::array::put_nullable_array_len(buf, len, flex); if let Some(v) = &self.standby_tasks { for it in v { it.encode(buf, version)?; } } } }
59 if version >= 0 { { let len = (self.warmup_tasks).as_ref().map(Vec::len); crate::primitives::array::put_nullable_array_len(buf, len, flex); if let Some(v) = &self.warmup_tasks { for it in v { it.encode(buf, version)?; } } } }
60 if version >= 0 { put_i32(buf, self.endpoint_information_epoch) }
61 if version >= 0 { { let len = (self.partitions_by_user_endpoint).as_ref().map(Vec::len); crate::primitives::array::put_nullable_array_len(buf, len, flex); if let Some(v) = &self.partitions_by_user_endpoint { for it in v { it.encode(buf, version)?; } } } }
62 if flex {
63 let tagged = WriteTaggedFields::new();
64 tagged.write(buf, &self.unknown_tagged_fields);
65 }
66 Ok(())
67 }
68 fn encoded_len(&self, version: i16) -> usize {
69 let flex = is_flexible(version);
70 let mut n: usize = 0;
71 if version >= 0 { n += 4; }
72 if version >= 0 { n += 2; }
73 if version >= 0 { n += if flex { compact_nullable_string_len(self.error_message.as_deref()) } else { nullable_string_len(self.error_message.as_deref()) }; }
74 if version >= 0 { n += if flex { compact_string_len(&self.member_id) } else { string_len(&self.member_id) }; }
75 if version >= 0 { n += 4; }
76 if version >= 0 { n += 4; }
77 if version >= 0 { n += 4; }
78 if version >= 0 { n += 4; }
79 if version >= 0 { n += { let opt: Option<&Vec<_>> = (self.status).as_ref(); let prefix = crate::primitives::array::nullable_array_len_prefix_len(opt.map(|v| v.len()), flex); let body: usize = opt.map_or(0, |v| v.iter().map(|it| it.encoded_len(version)).sum()); prefix + body }; }
80 if version >= 0 { n += { let opt: Option<&Vec<_>> = (self.active_tasks).as_ref(); let prefix = crate::primitives::array::nullable_array_len_prefix_len(opt.map(|v| v.len()), flex); let body: usize = opt.map_or(0, |v| v.iter().map(|it| it.encoded_len(version)).sum()); prefix + body }; }
81 if version >= 0 { n += { let opt: Option<&Vec<_>> = (self.standby_tasks).as_ref(); let prefix = crate::primitives::array::nullable_array_len_prefix_len(opt.map(|v| v.len()), flex); let body: usize = opt.map_or(0, |v| v.iter().map(|it| it.encoded_len(version)).sum()); prefix + body }; }
82 if version >= 0 { n += { let opt: Option<&Vec<_>> = (self.warmup_tasks).as_ref(); let prefix = crate::primitives::array::nullable_array_len_prefix_len(opt.map(|v| v.len()), flex); let body: usize = opt.map_or(0, |v| v.iter().map(|it| it.encoded_len(version)).sum()); prefix + body }; }
83 if version >= 0 { n += 4; }
84 if version >= 0 { n += { let opt: Option<&Vec<_>> = (self.partitions_by_user_endpoint).as_ref(); let prefix = crate::primitives::array::nullable_array_len_prefix_len(opt.map(|v| v.len()), flex); let body: usize = opt.map_or(0, |v| v.iter().map(|it| it.encoded_len(version)).sum()); prefix + body }; }
85 if flex {
86 let known_pairs: Vec<(u32, usize)> = Vec::new();
87 n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
88 }
89 n
90 }
91}
92
93impl<'de> Decode<'de> for StreamsGroupHeartbeatResponse {
94 fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
95 if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
96 return Err(ProtocolError::UnsupportedVersion { api_key: API_KEY, version });
97 }
98 let flex = is_flexible(version);
99 let mut out = Self::default();
100 if version >= 0 { out.throttle_time_ms = get_i32(buf)?; }
101 if version >= 0 { out.error_code = get_i16(buf)?; }
102 if version >= 0 { out.error_message = if flex { get_compact_nullable_string_owned(buf)? } else { get_nullable_string_owned(buf)? }; }
103 if version >= 0 { out.member_id = if flex { get_compact_string_owned(buf)? } else { get_string_owned(buf)? }; }
104 if version >= 0 { out.member_epoch = get_i32(buf)?; }
105 if version >= 0 { out.heartbeat_interval_ms = get_i32(buf)?; }
106 if version >= 0 { out.acceptable_recovery_lag = get_i32(buf)?; }
107 if version >= 0 { out.task_offset_interval_ms = get_i32(buf)?; }
108 if version >= 0 { out.status = { let opt = crate::primitives::array::get_nullable_array_len(buf, flex)?; match opt { None => None, Some(n) => { let mut v = Vec::with_capacity(n); for _ in 0..n { v.push(super::common::status::Status::decode(buf, version)?); } Some(v) } } }; }
109 if version >= 0 { out.active_tasks = { let opt = crate::primitives::array::get_nullable_array_len(buf, flex)?; match opt { None => None, Some(n) => { let mut v = Vec::with_capacity(n); for _ in 0..n { v.push(super::common::task_ids::TaskIds::decode(buf, version)?); } Some(v) } } }; }
110 if version >= 0 { out.standby_tasks = { let opt = crate::primitives::array::get_nullable_array_len(buf, flex)?; match opt { None => None, Some(n) => { let mut v = Vec::with_capacity(n); for _ in 0..n { v.push(super::common::task_ids::TaskIds::decode(buf, version)?); } Some(v) } } }; }
111 if version >= 0 { out.warmup_tasks = { let opt = crate::primitives::array::get_nullable_array_len(buf, flex)?; match opt { None => None, Some(n) => { let mut v = Vec::with_capacity(n); for _ in 0..n { v.push(super::common::task_ids::TaskIds::decode(buf, version)?); } Some(v) } } }; }
112 if version >= 0 { out.endpoint_information_epoch = get_i32(buf)?; }
113 if version >= 0 { out.partitions_by_user_endpoint = { let opt = crate::primitives::array::get_nullable_array_len(buf, flex)?; match opt { None => None, Some(n) => { let mut v = Vec::with_capacity(n); for _ in 0..n { v.push(EndpointToPartitions::decode(buf, version)?); } Some(v) } } }; }
114 if flex {
115 out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| {
116 Ok(false)
117 })?;
118 }
119 Ok(out)
120 }
121}
122
123#[derive(Debug, Clone, PartialEq, Eq, Default)]
124pub struct EndpointToPartitions {
125 pub user_endpoint: super::common::endpoint::Endpoint,
126 pub active_partitions: Vec<super::common::topic_partition::TopicPartition>,
127 pub standby_partitions: Vec<super::common::topic_partition::TopicPartition>,
128 pub unknown_tagged_fields: UnknownTaggedFields,
129}
130
131impl Encode for EndpointToPartitions {
132 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
133 let flex = version >= 0;
134 if version >= 0 { self.user_endpoint.encode(buf, version)? }
135 if version >= 0 { { crate::primitives::array::put_array_len(buf, (self.active_partitions).len(), flex); for it in &self.active_partitions { it.encode(buf, version)?; } } }
136 if version >= 0 { { crate::primitives::array::put_array_len(buf, (self.standby_partitions).len(), flex); for it in &self.standby_partitions { it.encode(buf, version)?; } } }
137 if flex {
138 let tagged = WriteTaggedFields::new();
139 tagged.write(buf, &self.unknown_tagged_fields);
140 }
141 Ok(())
142 }
143 fn encoded_len(&self, version: i16) -> usize {
144 let flex = version >= 0;
145 let mut n: usize = 0;
146 if version >= 0 { n += self.user_endpoint.encoded_len(version); }
147 if version >= 0 { n += { let prefix = crate::primitives::array::array_len_prefix_len((self.active_partitions).len(), flex); let body: usize = (self.active_partitions).iter().map(|it| it.encoded_len(version)).sum(); prefix + body }; }
148 if version >= 0 { n += { let prefix = crate::primitives::array::array_len_prefix_len((self.standby_partitions).len(), flex); let body: usize = (self.standby_partitions).iter().map(|it| it.encoded_len(version)).sum(); prefix + body }; }
149 if flex {
150 let known_pairs: Vec<(u32, usize)> = Vec::new();
151 n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
152 }
153 n
154 }
155}
156
157impl<'de> Decode<'de> for EndpointToPartitions {
158 fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
159 let flex = version >= 0;
160 let mut out = Self::default();
161 if version >= 0 { out.user_endpoint = super::common::endpoint::Endpoint::decode(buf, version)?; }
162 if version >= 0 { out.active_partitions = { let n = crate::primitives::array::get_array_len(buf, flex)?; let mut v = Vec::with_capacity(n); for _ in 0..n { v.push(super::common::topic_partition::TopicPartition::decode(buf, version)?); } v }; }
163 if version >= 0 { out.standby_partitions = { let n = crate::primitives::array::get_array_len(buf, flex)?; let mut v = Vec::with_capacity(n); for _ in 0..n { v.push(super::common::topic_partition::TopicPartition::decode(buf, version)?); } v }; }
164 if flex {
165 out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| {
166 Ok(false)
167 })?;
168 }
169 Ok(out)
170 }
171}
172
173#[must_use]
176#[allow(unused_comparisons)]
177pub fn default_json(version: i16) -> ::serde_json::Value {
178 let mut obj = ::serde_json::Map::new();
179 obj.insert("throttleTimeMs".to_string(), ::serde_json::json!(0));
180 obj.insert("errorCode".to_string(), ::serde_json::json!(0));
181 obj.insert("errorMessage".to_string(), ::serde_json::Value::Null);
182 obj.insert("memberId".to_string(), ::serde_json::Value::String(String::new()));
183 obj.insert("memberEpoch".to_string(), ::serde_json::json!(0));
184 obj.insert("heartbeatIntervalMs".to_string(), ::serde_json::json!(0));
185 obj.insert("acceptableRecoveryLag".to_string(), ::serde_json::json!(0));
186 obj.insert("taskOffsetIntervalMs".to_string(), ::serde_json::json!(0));
187 obj.insert("status".to_string(), ::serde_json::Value::Null);
188 obj.insert("activeTasks".to_string(), ::serde_json::Value::Null);
189 obj.insert("standbyTasks".to_string(), ::serde_json::Value::Null);
190 obj.insert("warmupTasks".to_string(), ::serde_json::Value::Null);
191 obj.insert("endpointInformationEpoch".to_string(), ::serde_json::json!(0));
192 obj.insert("partitionsByUserEndpoint".to_string(), ::serde_json::Value::Null);
193 ::serde_json::Value::Object(obj)
194}