kacrab-protocol 0.1.0

Kafka wire protocol types — generated from upstream message schemas by `kacrab-codegen`.
Documentation
//! Generated from ShareGroupHeartbeatRequest.json - DO NOT EDIT
#![allow(
    missing_docs,
    clippy::all,
    clippy::pedantic,
    clippy::nursery,
    clippy::arithmetic_side_effects,
    reason = "Generated protocol modules mirror Kafka's schema shape and intentionally trade \
              hand-written lint style for reproducible wire-code output."
)]
use bytes::{Bytes, BytesMut};

use crate::*;

#[derive(Debug, Clone, PartialEq)]
pub struct ShareGroupHeartbeatRequestData {
    /// The group identifier.
    pub group_id: KafkaString,
    /// The member id generated by the consumer. The member id must be kept during the entire
    /// lifetime of the consumer process.
    pub member_id: KafkaString,
    /// The current member epoch; 0 to join the group; -1 to leave the group.
    pub member_epoch: i32,
    /// null if not provided or if it didn't change since the last heartbeat; the rack ID of
    /// consumer otherwise.
    pub rack_id: Option<KafkaString>,
    /// null if it didn't change since the last heartbeat; the subscribed topic names otherwise.
    pub subscribed_topic_names: Option<Vec<KafkaString>>,
    pub _unknown_tagged_fields: Vec<RawTaggedField>,
}
impl Default for ShareGroupHeartbeatRequestData {
    fn default() -> Self {
        Self {
            group_id: KafkaString::default(),
            member_id: KafkaString::default(),
            member_epoch: 0_i32,
            rack_id: None,
            subscribed_topic_names: None,
            _unknown_tagged_fields: Vec::new(),
        }
    }
}
impl ShareGroupHeartbeatRequestData {
    pub fn with_group_id(mut self, value: KafkaString) -> Self {
        self.group_id = value;
        self
    }
    pub fn with_member_id(mut self, value: KafkaString) -> Self {
        self.member_id = value;
        self
    }
    pub fn with_member_epoch(mut self, value: i32) -> Self {
        self.member_epoch = value;
        self
    }
    pub fn with_rack_id(mut self, value: Option<KafkaString>) -> Self {
        self.rack_id = value;
        self
    }
    pub fn with_subscribed_topic_names(mut self, value: Option<Vec<KafkaString>>) -> Self {
        self.subscribed_topic_names = value;
        self
    }
    pub fn read(buf: &mut Bytes, version: i16) -> Result<Self> {
        if version < 1 || version > 1 {
            return Err(UnsupportedVersion::new(76, version).into());
        }
        let group_id;
        let member_id;
        let member_epoch;
        let rack_id;
        let subscribed_topic_names;
        let mut _unknown_tagged_fields: Vec<RawTaggedField> = Vec::new();
        group_id = read_compact_string(buf)?;
        member_id = read_compact_string(buf)?;
        member_epoch = read_i32(buf)?;
        rack_id = read_compact_nullable_string(buf)?;
        subscribed_topic_names = {
            let len = read_compact_array_length(buf)?;
            if len < 0 {
                None
            } else {
                let mut arr = Vec::with_capacity(len as usize);
                for _ in 0..len {
                    arr.push(read_compact_string(buf)?);
                }
                Some(arr)
            }
        };
        let tagged_fields = read_tagged_fields(buf)?;
        for field in &tagged_fields {
            match field.tag {
                _ => {
                    _unknown_tagged_fields.push(field.clone());
                },
            }
        }
        Ok(Self {
            group_id,
            member_id,
            member_epoch,
            rack_id,
            subscribed_topic_names,
            _unknown_tagged_fields,
        })
    }
    pub fn write(&self, buf: &mut BytesMut, version: i16) -> Result<()> {
        if version < 1 || version > 1 {
            return Err(UnsupportedVersion::new(76, version).into());
        }
        write_compact_string(buf, &self.group_id)?;
        write_compact_string(buf, &self.member_id)?;
        write_i32(buf, self.member_epoch);
        write_compact_nullable_string(buf, self.rack_id.as_ref())?;
        match &self.subscribed_topic_names {
            None => {
                write_compact_array_length(buf, -1);
            },
            Some(arr) => {
                write_compact_array_length(buf, arr.len() as i32);
                for el in arr {
                    write_compact_string(buf, el)?;
                }
            },
        }
        let mut all_tags: Vec<RawTaggedField> = self._unknown_tagged_fields.clone();
        all_tags.sort_by_key(|f| f.tag);
        write_tagged_fields(buf, &all_tags)?;
        Ok(())
    }
    pub fn encoded_len(&self, version: i16) -> Result<usize> {
        if version < 1 || version > 1 {
            return Err(UnsupportedVersion::new(76, version).into());
        }
        let mut len: usize = 0;
        len += compact_string_len(&self.group_id)?;
        len += compact_string_len(&self.member_id)?;
        len += 4;
        len += compact_nullable_string_len(self.rack_id.as_ref())?;
        match &self.subscribed_topic_names {
            None => {
                len += compact_array_length_len(-1);
            },
            Some(arr) => {
                len += compact_array_length_len(arr.len() as i32);
                for el in arr {
                    len += compact_string_len(el)?;
                }
            },
        }
        let mut all_tags: Vec<RawTaggedField> = self._unknown_tagged_fields.clone();
        all_tags.sort_by_key(|f| f.tag);
        len += tagged_fields_len(&all_tags)?;
        Ok(len)
    }
}