Skip to main content

crabka_protocol/opt/rustwide/workdir/generated/
StreamsGroupHeartbeatResponse.borrowed.rs

1// AUTO-GENERATED by crabka-protocol-codegen against a9ce3221537b8653448750697915607dc7936cf3. Do not edit.
2
3use bytes::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, nullable_string_len,
8    put_compact_nullable_string, put_compact_string, put_nullable_string, put_string, string_len,
9};
10use crate::primitives::string_bytes_borrowed::{
11    get_compact_nullable_string_borrowed, get_compact_string_borrowed,
12    get_nullable_string_borrowed, get_string_borrowed,
13};
14use crate::tagged_fields::{WriteTaggedFields, read_tagged_fields, tagged_fields_len};
15use crate::{DecodeBorrow, Encode, ProtocolError, UnknownTaggedFields};
16
17pub const API_KEY: i16 = 88;
18pub const MIN_VERSION: i16 = 0;
19pub const MAX_VERSION: i16 = 0;
20pub const FLEXIBLE_MIN: i16 = 0;
21
22#[inline]
23fn is_flexible(version: i16) -> bool {
24    version >= FLEXIBLE_MIN
25}
26
27#[derive(Debug, Clone, PartialEq, Eq, Default)]
28pub struct StreamsGroupHeartbeatResponse<'a> {
29    pub throttle_time_ms: i32,
30    pub error_code: i16,
31    pub error_message: Option<&'a str>,
32    pub member_id: &'a str,
33    pub member_epoch: i32,
34    pub heartbeat_interval_ms: i32,
35    pub acceptable_recovery_lag: i32,
36    pub task_offset_interval_ms: i32,
37    pub status: Option<Vec<super::common::streams_group_heartbeat_response::status::Status<'a>>>,
38    pub active_tasks:
39        Option<Vec<super::common::streams_group_heartbeat_response::task_ids::TaskIds<'a>>>,
40    pub standby_tasks:
41        Option<Vec<super::common::streams_group_heartbeat_response::task_ids::TaskIds<'a>>>,
42    pub warmup_tasks:
43        Option<Vec<super::common::streams_group_heartbeat_response::task_ids::TaskIds<'a>>>,
44    pub endpoint_information_epoch: i32,
45    pub partitions_by_user_endpoint: Option<Vec<EndpointToPartitions<'a>>>,
46    pub unknown_tagged_fields: UnknownTaggedFields,
47}
48impl StreamsGroupHeartbeatResponse<'_> {
49    pub fn to_owned(
50        &self,
51    ) -> crate::owned::streams_group_heartbeat_response::StreamsGroupHeartbeatResponse {
52        crate::owned::streams_group_heartbeat_response::StreamsGroupHeartbeatResponse {
53            throttle_time_ms: (self.throttle_time_ms),
54            error_code: (self.error_code),
55            error_message: (self.error_message).map(std::string::ToString::to_string),
56            member_id: (self.member_id).to_string(),
57            member_epoch: (self.member_epoch),
58            heartbeat_interval_ms: (self.heartbeat_interval_ms),
59            acceptable_recovery_lag: (self.acceptable_recovery_lag),
60            task_offset_interval_ms: (self.task_offset_interval_ms),
61            status: (self.status)
62                .as_ref()
63                .map(|v| v.iter().map(super::common::streams_group_heartbeat_response::status::Status::to_owned).collect()),
64            active_tasks: (self.active_tasks)
65                .as_ref()
66                .map(|v| v.iter().map(super::common::streams_group_heartbeat_response::task_ids::TaskIds::to_owned).collect()),
67            standby_tasks: (self.standby_tasks)
68                .as_ref()
69                .map(|v| v.iter().map(super::common::streams_group_heartbeat_response::task_ids::TaskIds::to_owned).collect()),
70            warmup_tasks: (self.warmup_tasks)
71                .as_ref()
72                .map(|v| v.iter().map(super::common::streams_group_heartbeat_response::task_ids::TaskIds::to_owned).collect()),
73            endpoint_information_epoch: (self.endpoint_information_epoch),
74            partitions_by_user_endpoint: (self.partitions_by_user_endpoint)
75                .as_ref()
76                .map(|v| v.iter().map(EndpointToPartitions::to_owned).collect()),
77            unknown_tagged_fields: self.unknown_tagged_fields.clone(),
78        }
79    }
80}
81impl Encode for StreamsGroupHeartbeatResponse<'_> {
82    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
83        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
84            return Err(ProtocolError::UnsupportedVersion {
85                api_key: API_KEY,
86                version,
87            });
88        }
89        let flex = is_flexible(version);
90        if version >= 0 {
91            put_i32(buf, self.throttle_time_ms);
92        }
93        if version >= 0 {
94            put_i16(buf, self.error_code);
95        }
96        if version >= 0 {
97            if flex {
98                put_compact_nullable_string(buf, self.error_message);
99            } else {
100                put_nullable_string(buf, self.error_message);
101            }
102        }
103        if version >= 0 {
104            if flex {
105                put_compact_string(buf, self.member_id);
106            } else {
107                put_string(buf, self.member_id);
108            }
109        }
110        if version >= 0 {
111            put_i32(buf, self.member_epoch);
112        }
113        if version >= 0 {
114            put_i32(buf, self.heartbeat_interval_ms);
115        }
116        if version >= 0 {
117            put_i32(buf, self.acceptable_recovery_lag);
118        }
119        if version >= 0 {
120            put_i32(buf, self.task_offset_interval_ms);
121        }
122        if version >= 0 {
123            {
124                let len = (self.status).as_ref().map(Vec::len);
125                crate::primitives::array::put_nullable_array_len(buf, len, flex);
126                if let Some(v) = &self.status {
127                    for it in v {
128                        it.encode(buf, version)?;
129                    }
130                }
131            }
132        }
133        if version >= 0 {
134            {
135                let len = (self.active_tasks).as_ref().map(Vec::len);
136                crate::primitives::array::put_nullable_array_len(buf, len, flex);
137                if let Some(v) = &self.active_tasks {
138                    for it in v {
139                        it.encode(buf, version)?;
140                    }
141                }
142            }
143        }
144        if version >= 0 {
145            {
146                let len = (self.standby_tasks).as_ref().map(Vec::len);
147                crate::primitives::array::put_nullable_array_len(buf, len, flex);
148                if let Some(v) = &self.standby_tasks {
149                    for it in v {
150                        it.encode(buf, version)?;
151                    }
152                }
153            }
154        }
155        if version >= 0 {
156            {
157                let len = (self.warmup_tasks).as_ref().map(Vec::len);
158                crate::primitives::array::put_nullable_array_len(buf, len, flex);
159                if let Some(v) = &self.warmup_tasks {
160                    for it in v {
161                        it.encode(buf, version)?;
162                    }
163                }
164            }
165        }
166        if version >= 0 {
167            put_i32(buf, self.endpoint_information_epoch);
168        }
169        if version >= 0 {
170            {
171                let len = (self.partitions_by_user_endpoint).as_ref().map(Vec::len);
172                crate::primitives::array::put_nullable_array_len(buf, len, flex);
173                if let Some(v) = &self.partitions_by_user_endpoint {
174                    for it in v {
175                        it.encode(buf, version)?;
176                    }
177                }
178            }
179        }
180        if flex {
181            let tagged = WriteTaggedFields::new();
182            tagged.write(buf, &self.unknown_tagged_fields);
183        }
184        Ok(())
185    }
186    fn encoded_len(&self, version: i16) -> usize {
187        let flex = is_flexible(version);
188        let mut n: usize = 0;
189        if version >= 0 {
190            n += 4;
191        }
192        if version >= 0 {
193            n += 2;
194        }
195        if version >= 0 {
196            n += if flex {
197                compact_nullable_string_len(self.error_message)
198            } else {
199                nullable_string_len(self.error_message)
200            };
201        }
202        if version >= 0 {
203            n += if flex {
204                compact_string_len(self.member_id)
205            } else {
206                string_len(self.member_id)
207            };
208        }
209        if version >= 0 {
210            n += 4;
211        }
212        if version >= 0 {
213            n += 4;
214        }
215        if version >= 0 {
216            n += 4;
217        }
218        if version >= 0 {
219            n += 4;
220        }
221        if version >= 0 {
222            n += {
223                let opt: Option<&Vec<_>> = (self.status).as_ref();
224                let prefix = crate::primitives::array::nullable_array_len_prefix_len(
225                    opt.map(std::vec::Vec::len),
226                    flex,
227                );
228                let body: usize =
229                    opt.map_or(0, |v| v.iter().map(|it| it.encoded_len(version)).sum());
230                prefix + body
231            };
232        }
233        if version >= 0 {
234            n += {
235                let opt: Option<&Vec<_>> = (self.active_tasks).as_ref();
236                let prefix = crate::primitives::array::nullable_array_len_prefix_len(
237                    opt.map(std::vec::Vec::len),
238                    flex,
239                );
240                let body: usize =
241                    opt.map_or(0, |v| v.iter().map(|it| it.encoded_len(version)).sum());
242                prefix + body
243            };
244        }
245        if version >= 0 {
246            n += {
247                let opt: Option<&Vec<_>> = (self.standby_tasks).as_ref();
248                let prefix = crate::primitives::array::nullable_array_len_prefix_len(
249                    opt.map(std::vec::Vec::len),
250                    flex,
251                );
252                let body: usize =
253                    opt.map_or(0, |v| v.iter().map(|it| it.encoded_len(version)).sum());
254                prefix + body
255            };
256        }
257        if version >= 0 {
258            n += {
259                let opt: Option<&Vec<_>> = (self.warmup_tasks).as_ref();
260                let prefix = crate::primitives::array::nullable_array_len_prefix_len(
261                    opt.map(std::vec::Vec::len),
262                    flex,
263                );
264                let body: usize =
265                    opt.map_or(0, |v| v.iter().map(|it| it.encoded_len(version)).sum());
266                prefix + body
267            };
268        }
269        if version >= 0 {
270            n += 4;
271        }
272        if version >= 0 {
273            n += {
274                let opt: Option<&Vec<_>> = (self.partitions_by_user_endpoint).as_ref();
275                let prefix = crate::primitives::array::nullable_array_len_prefix_len(
276                    opt.map(std::vec::Vec::len),
277                    flex,
278                );
279                let body: usize =
280                    opt.map_or(0, |v| v.iter().map(|it| it.encoded_len(version)).sum());
281                prefix + body
282            };
283        }
284        if flex {
285            let known_pairs: Vec<(u32, usize)> = Vec::new();
286            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
287        }
288        n
289    }
290}
291impl<'de> DecodeBorrow<'de> for StreamsGroupHeartbeatResponse<'de> {
292    fn decode_borrow(buf: &mut &'de [u8], version: i16) -> Result<Self, ProtocolError> {
293        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
294            return Err(ProtocolError::UnsupportedVersion {
295                api_key: API_KEY,
296                version,
297            });
298        }
299        let flex = is_flexible(version);
300        let mut out = Self::default();
301        if version >= 0 {
302            out.throttle_time_ms = get_i32(buf)?;
303        }
304        if version >= 0 {
305            out.error_code = get_i16(buf)?;
306        }
307        if version >= 0 {
308            out.error_message = if flex {
309                get_compact_nullable_string_borrowed(buf)?
310            } else {
311                get_nullable_string_borrowed(buf)?
312            };
313        }
314        if version >= 0 {
315            out.member_id = if flex {
316                get_compact_string_borrowed(buf)?
317            } else {
318                get_string_borrowed(buf)?
319            };
320        }
321        if version >= 0 {
322            out.member_epoch = get_i32(buf)?;
323        }
324        if version >= 0 {
325            out.heartbeat_interval_ms = get_i32(buf)?;
326        }
327        if version >= 0 {
328            out.acceptable_recovery_lag = get_i32(buf)?;
329        }
330        if version >= 0 {
331            out.task_offset_interval_ms = get_i32(buf)?;
332        }
333        if version >= 0 {
334            out.status = {
335                let opt = crate::primitives::array::get_nullable_array_len(buf, flex)?;
336                match opt {
337                    None => None,
338                    Some(n) => {
339                        let mut v = Vec::with_capacity(n);
340                        for _ in 0..n {
341                            v . push (super :: common :: streams_group_heartbeat_response :: status :: Status :: decode_borrow (buf , version) ?) ;
342                        }
343                        Some(v)
344                    }
345                }
346            };
347        }
348        if version >= 0 {
349            out.active_tasks = {
350                let opt = crate::primitives::array::get_nullable_array_len(buf, flex)?;
351                match opt {
352                    None => None,
353                    Some(n) => {
354                        let mut v = Vec::with_capacity(n);
355                        for _ in 0..n {
356                            v . push (super :: common :: streams_group_heartbeat_response :: task_ids :: TaskIds :: decode_borrow (buf , version) ?) ;
357                        }
358                        Some(v)
359                    }
360                }
361            };
362        }
363        if version >= 0 {
364            out.standby_tasks = {
365                let opt = crate::primitives::array::get_nullable_array_len(buf, flex)?;
366                match opt {
367                    None => None,
368                    Some(n) => {
369                        let mut v = Vec::with_capacity(n);
370                        for _ in 0..n {
371                            v . push (super :: common :: streams_group_heartbeat_response :: task_ids :: TaskIds :: decode_borrow (buf , version) ?) ;
372                        }
373                        Some(v)
374                    }
375                }
376            };
377        }
378        if version >= 0 {
379            out.warmup_tasks = {
380                let opt = crate::primitives::array::get_nullable_array_len(buf, flex)?;
381                match opt {
382                    None => None,
383                    Some(n) => {
384                        let mut v = Vec::with_capacity(n);
385                        for _ in 0..n {
386                            v . push (super :: common :: streams_group_heartbeat_response :: task_ids :: TaskIds :: decode_borrow (buf , version) ?) ;
387                        }
388                        Some(v)
389                    }
390                }
391            };
392        }
393        if version >= 0 {
394            out.endpoint_information_epoch = get_i32(buf)?;
395        }
396        if version >= 0 {
397            out.partitions_by_user_endpoint = {
398                let opt = crate::primitives::array::get_nullable_array_len(buf, flex)?;
399                match opt {
400                    None => None,
401                    Some(n) => {
402                        let mut v = Vec::with_capacity(n);
403                        for _ in 0..n {
404                            v.push(EndpointToPartitions::decode_borrow(buf, version)?);
405                        }
406                        Some(v)
407                    }
408                }
409            };
410        }
411        if flex {
412            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
413        }
414        Ok(out)
415    }
416}
417#[cfg(test)]
418impl StreamsGroupHeartbeatResponse<'_> {
419    #[must_use]
420    pub fn populated(version: i16) -> Self {
421        let mut m = Self::default();
422        if version >= 0 {
423            m.throttle_time_ms = 1i32;
424        }
425        if version >= 0 {
426            m.error_code = 1i16;
427        }
428        if version >= 0 {
429            m.error_message = Some("x");
430        }
431        if version >= 0 {
432            m.member_id = "x";
433        }
434        if version >= 0 {
435            m.member_epoch = 1i32;
436        }
437        if version >= 0 {
438            m.heartbeat_interval_ms = 1i32;
439        }
440        if version >= 0 {
441            m.acceptable_recovery_lag = 1i32;
442        }
443        if version >= 0 {
444            m.task_offset_interval_ms = 1i32;
445        }
446        if version >= 0 {
447            m.status = Some(vec![
448                super::common::streams_group_heartbeat_response::status::Status::populated(version),
449            ]);
450        }
451        if version >= 0 {
452            m.active_tasks = Some(vec![
453                super::common::streams_group_heartbeat_response::task_ids::TaskIds::populated(
454                    version,
455                ),
456            ]);
457        }
458        if version >= 0 {
459            m.standby_tasks = Some(vec![
460                super::common::streams_group_heartbeat_response::task_ids::TaskIds::populated(
461                    version,
462                ),
463            ]);
464        }
465        if version >= 0 {
466            m.warmup_tasks = Some(vec![
467                super::common::streams_group_heartbeat_response::task_ids::TaskIds::populated(
468                    version,
469                ),
470            ]);
471        }
472        if version >= 0 {
473            m.endpoint_information_epoch = 1i32;
474        }
475        if version >= 0 {
476            m.partitions_by_user_endpoint = Some(vec![EndpointToPartitions::populated(version)]);
477        }
478        m
479    }
480}
481#[derive(Debug, Clone, PartialEq, Eq, Default)]
482pub struct EndpointToPartitions<'a> {
483    pub user_endpoint: super::common::streams_group_heartbeat_response::endpoint::Endpoint<'a>,
484    pub active_partitions:
485        Vec<super::common::streams_group_heartbeat_response::topic_partition::TopicPartition<'a>>,
486    pub standby_partitions:
487        Vec<super::common::streams_group_heartbeat_response::topic_partition::TopicPartition<'a>>,
488    pub unknown_tagged_fields: UnknownTaggedFields,
489}
490impl EndpointToPartitions<'_> {
491    pub fn to_owned(&self) -> crate::owned::streams_group_heartbeat_response::EndpointToPartitions {
492        crate::owned::streams_group_heartbeat_response::EndpointToPartitions {
493            user_endpoint: (self.user_endpoint).to_owned(),
494            active_partitions: (self.active_partitions)
495                .iter()
496                .map(super::common::streams_group_heartbeat_response::topic_partition::TopicPartition::to_owned)
497                .collect(),
498            standby_partitions: (self.standby_partitions)
499                .iter()
500                .map(super::common::streams_group_heartbeat_response::topic_partition::TopicPartition::to_owned)
501                .collect(),
502            unknown_tagged_fields: self.unknown_tagged_fields.clone(),
503        }
504    }
505}
506impl Encode for EndpointToPartitions<'_> {
507    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
508        let flex = version >= 0;
509        if version >= 0 {
510            self.user_endpoint.encode(buf, version)?;
511        }
512        if version >= 0 {
513            {
514                crate::primitives::array::put_array_len(buf, (self.active_partitions).len(), flex);
515                for it in &self.active_partitions {
516                    it.encode(buf, version)?;
517                }
518            }
519        }
520        if version >= 0 {
521            {
522                crate::primitives::array::put_array_len(buf, (self.standby_partitions).len(), flex);
523                for it in &self.standby_partitions {
524                    it.encode(buf, version)?;
525                }
526            }
527        }
528        if flex {
529            let tagged = WriteTaggedFields::new();
530            tagged.write(buf, &self.unknown_tagged_fields);
531        }
532        Ok(())
533    }
534    fn encoded_len(&self, version: i16) -> usize {
535        let flex = version >= 0;
536        let mut n: usize = 0;
537        if version >= 0 {
538            n += self.user_endpoint.encoded_len(version);
539        }
540        if version >= 0 {
541            n += {
542                let prefix = crate::primitives::array::array_len_prefix_len(
543                    (self.active_partitions).len(),
544                    flex,
545                );
546                let body: usize = (self.active_partitions)
547                    .iter()
548                    .map(|it| it.encoded_len(version))
549                    .sum();
550                prefix + body
551            };
552        }
553        if version >= 0 {
554            n += {
555                let prefix = crate::primitives::array::array_len_prefix_len(
556                    (self.standby_partitions).len(),
557                    flex,
558                );
559                let body: usize = (self.standby_partitions)
560                    .iter()
561                    .map(|it| it.encoded_len(version))
562                    .sum();
563                prefix + body
564            };
565        }
566        if flex {
567            let known_pairs: Vec<(u32, usize)> = Vec::new();
568            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
569        }
570        n
571    }
572}
573impl<'de> DecodeBorrow<'de> for EndpointToPartitions<'de> {
574    fn decode_borrow(buf: &mut &'de [u8], version: i16) -> Result<Self, ProtocolError> {
575        let flex = version >= 0;
576        let mut out = Self::default();
577        if version >= 0 {
578            out.user_endpoint =
579                super::common::streams_group_heartbeat_response::endpoint::Endpoint::decode_borrow(
580                    buf, version,
581                )?;
582        }
583        if version >= 0 {
584            out.active_partitions = {
585                let n = crate::primitives::array::get_array_len(buf, flex)?;
586                let mut v = Vec::with_capacity(n);
587                for _ in 0..n {
588                    v . push (super :: common :: streams_group_heartbeat_response :: topic_partition :: TopicPartition :: decode_borrow (buf , version) ?) ;
589                }
590                v
591            };
592        }
593        if version >= 0 {
594            out.standby_partitions = {
595                let n = crate::primitives::array::get_array_len(buf, flex)?;
596                let mut v = Vec::with_capacity(n);
597                for _ in 0..n {
598                    v . push (super :: common :: streams_group_heartbeat_response :: topic_partition :: TopicPartition :: decode_borrow (buf , version) ?) ;
599                }
600                v
601            };
602        }
603        if flex {
604            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
605        }
606        Ok(out)
607    }
608}
609#[cfg(test)]
610impl EndpointToPartitions<'_> {
611    #[must_use]
612    pub fn populated(version: i16) -> Self {
613        let mut m = Self::default();
614        if version >= 0 {
615            m.user_endpoint =
616                super::common::streams_group_heartbeat_response::endpoint::Endpoint::populated(
617                    version,
618                );
619        }
620        if version >= 0 {
621            m . active_partitions = vec ! [super :: common :: streams_group_heartbeat_response :: topic_partition :: TopicPartition :: populated (version)] ;
622        }
623        if version >= 0 {
624            m . standby_partitions = vec ! [super :: common :: streams_group_heartbeat_response :: topic_partition :: TopicPartition :: populated (version)] ;
625        }
626        m
627    }
628}