Skip to main content

kacrab_protocol/generated/
request_header.rs

1//! Generated from RequestHeader.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 RequestHeaderData {
17    /// The API key of this request.
18    pub request_api_key: i16,
19    /// The API version of this request.
20    pub request_api_version: i16,
21    /// The correlation ID of this request.
22    pub correlation_id: i32,
23    /// The client ID string.
24    pub client_id: Option<KafkaString>,
25    pub _unknown_tagged_fields: Vec<RawTaggedField>,
26}
27impl Default for RequestHeaderData {
28    fn default() -> Self {
29        Self {
30            request_api_key: 0_i16,
31            request_api_version: 0_i16,
32            correlation_id: 0_i32,
33            client_id: None,
34            _unknown_tagged_fields: Vec::new(),
35        }
36    }
37}
38impl RequestHeaderData {
39    pub fn with_request_api_key(mut self, value: i16) -> Self {
40        self.request_api_key = value;
41        self
42    }
43    pub fn with_request_api_version(mut self, value: i16) -> Self {
44        self.request_api_version = value;
45        self
46    }
47    pub fn with_correlation_id(mut self, value: i32) -> Self {
48        self.correlation_id = value;
49        self
50    }
51    pub fn with_client_id(mut self, value: Option<KafkaString>) -> Self {
52        self.client_id = value;
53        self
54    }
55    pub fn read(buf: &mut Bytes, version: i16) -> Result<Self> {
56        let request_api_key;
57        let request_api_version;
58        let correlation_id;
59        let client_id;
60        let mut _unknown_tagged_fields: Vec<RawTaggedField> = Vec::new();
61        request_api_key = read_i16(buf)?;
62        request_api_version = read_i16(buf)?;
63        correlation_id = read_i32(buf)?;
64        client_id = read_nullable_string(buf)?;
65        if version >= 2 {
66            let tagged_fields = read_tagged_fields(buf)?;
67            for field in &tagged_fields {
68                match field.tag {
69                    _ => {
70                        _unknown_tagged_fields.push(field.clone());
71                    },
72                }
73            }
74        }
75        Ok(Self {
76            request_api_key,
77            request_api_version,
78            correlation_id,
79            client_id,
80            _unknown_tagged_fields,
81        })
82    }
83    pub fn write(&self, buf: &mut BytesMut, version: i16) -> Result<()> {
84        write_i16(buf, self.request_api_key);
85        write_i16(buf, self.request_api_version);
86        write_i32(buf, self.correlation_id);
87        write_nullable_string(buf, self.client_id.as_ref())?;
88        if version >= 2 {
89            let mut all_tags: Vec<RawTaggedField> = self._unknown_tagged_fields.clone();
90            all_tags.sort_by_key(|f| f.tag);
91            write_tagged_fields(buf, &all_tags)?;
92        }
93        Ok(())
94    }
95    pub fn encoded_len(&self, version: i16) -> Result<usize> {
96        let mut len: usize = 0;
97        len += 2;
98        len += 2;
99        len += 4;
100        len += nullable_string_len(self.client_id.as_ref())?;
101        if version >= 2 {
102            let mut all_tags: Vec<RawTaggedField> = self._unknown_tagged_fields.clone();
103            all_tags.sort_by_key(|f| f.tag);
104            len += tagged_fields_len(&all_tags)?;
105        }
106        Ok(len)
107    }
108}