Skip to main content

kacrab_protocol/generated/
heartbeat_response.rs

1//! Generated from HeartbeatResponse.json - DO NOT EDIT
2#![allow(
3    missing_docs,
4    clippy::all,
5    clippy::pedantic,
6    clippy::nursery,
7    clippy::arithmetic_side_effects,
8    reason = "Generated protocol modules mirror Kafka's schema shape and intentionally trade \
9              hand-written lint style for reproducible wire-code output."
10)]
11use bytes::{Bytes, BytesMut};
12
13use crate::*;
14
15#[derive(Debug, Clone, PartialEq)]
16pub struct HeartbeatResponseData {
17    /// The duration in milliseconds for which the request was throttled due to a quota violation,
18    /// or zero if the request did not violate any quota.
19    pub throttle_time_ms: i32,
20    /// The error code, or 0 if there was no error.
21    pub error_code: i16,
22    pub _unknown_tagged_fields: Vec<RawTaggedField>,
23}
24impl Default for HeartbeatResponseData {
25    fn default() -> Self {
26        Self {
27            throttle_time_ms: 0_i32,
28            error_code: 0_i16,
29            _unknown_tagged_fields: Vec::new(),
30        }
31    }
32}
33impl HeartbeatResponseData {
34    pub fn with_throttle_time_ms(mut self, value: i32) -> Self {
35        self.throttle_time_ms = value;
36        self
37    }
38    pub fn with_error_code(mut self, value: i16) -> Self {
39        self.error_code = value;
40        self
41    }
42    pub fn read(buf: &mut Bytes, version: i16) -> Result<Self> {
43        if version < 0 || version > 4 {
44            return Err(UnsupportedVersion::new(12, version).into());
45        }
46        let mut throttle_time_ms = 0_i32;
47        let error_code;
48        let mut _unknown_tagged_fields: Vec<RawTaggedField> = Vec::new();
49        if version >= 1 {
50            throttle_time_ms = read_i32(buf)?;
51        }
52        error_code = read_i16(buf)?;
53        if version >= 4 {
54            let tagged_fields = read_tagged_fields(buf)?;
55            for field in &tagged_fields {
56                match field.tag {
57                    _ => {
58                        _unknown_tagged_fields.push(field.clone());
59                    },
60                }
61            }
62        }
63        Ok(Self {
64            throttle_time_ms,
65            error_code,
66            _unknown_tagged_fields,
67        })
68    }
69    pub fn write(&self, buf: &mut BytesMut, version: i16) -> Result<()> {
70        if version < 0 || version > 4 {
71            return Err(UnsupportedVersion::new(12, version).into());
72        }
73        if version >= 1 {
74            write_i32(buf, self.throttle_time_ms);
75        } else if self.throttle_time_ms != 0_i32 {
76            return Err(UnsupportedFieldVersion::new(12, "throttle_time_ms", version).into());
77        }
78        write_i16(buf, self.error_code);
79        if version >= 4 {
80            let mut all_tags: Vec<RawTaggedField> = self._unknown_tagged_fields.clone();
81            all_tags.sort_by_key(|f| f.tag);
82            write_tagged_fields(buf, &all_tags)?;
83        }
84        Ok(())
85    }
86    pub fn encoded_len(&self, version: i16) -> Result<usize> {
87        if version < 0 || version > 4 {
88            return Err(UnsupportedVersion::new(12, version).into());
89        }
90        let mut len: usize = 0;
91        if version >= 1 {
92            len += 4;
93        } else if self.throttle_time_ms != 0_i32 {
94            return Err(UnsupportedFieldVersion::new(12, "throttle_time_ms", version).into());
95        }
96        len += 2;
97        if version >= 4 {
98            let mut all_tags: Vec<RawTaggedField> = self._unknown_tagged_fields.clone();
99            all_tags.sort_by_key(|f| f.tag);
100            len += tagged_fields_len(&all_tags)?;
101        }
102        Ok(len)
103    }
104}