Skip to main content

kacrab_protocol/generated/
default_principal_data.rs

1//! Generated from DefaultPrincipalData.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 DefaultPrincipalDataData {
17    /// The principal type.
18    pub r#type: KafkaString,
19    /// The principal name.
20    pub name: KafkaString,
21    /// Whether the principal was authenticated by a delegation token on the forwarding broker.
22    pub token_authenticated: bool,
23    pub _unknown_tagged_fields: Vec<RawTaggedField>,
24}
25impl Default for DefaultPrincipalDataData {
26    fn default() -> Self {
27        Self {
28            r#type: KafkaString::default(),
29            name: KafkaString::default(),
30            token_authenticated: false,
31            _unknown_tagged_fields: Vec::new(),
32        }
33    }
34}
35impl DefaultPrincipalDataData {
36    pub fn with_type(mut self, value: KafkaString) -> Self {
37        self.r#type = value;
38        self
39    }
40    pub fn with_name(mut self, value: KafkaString) -> Self {
41        self.name = value;
42        self
43    }
44    pub fn with_token_authenticated(mut self, value: bool) -> Self {
45        self.token_authenticated = value;
46        self
47    }
48    pub fn read(buf: &mut Bytes, _version: i16) -> Result<Self> {
49        let r#type;
50        let name;
51        let token_authenticated;
52        let mut _unknown_tagged_fields: Vec<RawTaggedField> = Vec::new();
53        r#type = read_compact_string(buf)?;
54        name = read_compact_string(buf)?;
55        token_authenticated = read_bool(buf)?;
56        let tagged_fields = read_tagged_fields(buf)?;
57        for field in &tagged_fields {
58            match field.tag {
59                _ => {
60                    _unknown_tagged_fields.push(field.clone());
61                },
62            }
63        }
64        Ok(Self {
65            r#type,
66            name,
67            token_authenticated,
68            _unknown_tagged_fields,
69        })
70    }
71    pub fn write(&self, buf: &mut BytesMut, _version: i16) -> Result<()> {
72        write_compact_string(buf, &self.r#type)?;
73        write_compact_string(buf, &self.name)?;
74        write_bool(buf, self.token_authenticated);
75        let mut all_tags: Vec<RawTaggedField> = self._unknown_tagged_fields.clone();
76        all_tags.sort_by_key(|f| f.tag);
77        write_tagged_fields(buf, &all_tags)?;
78        Ok(())
79    }
80    pub fn encoded_len(&self, _version: i16) -> Result<usize> {
81        let mut len: usize = 0;
82        len += compact_string_len(&self.r#type)?;
83        len += compact_string_len(&self.name)?;
84        len += 1;
85        let mut all_tags: Vec<RawTaggedField> = self._unknown_tagged_fields.clone();
86        all_tags.sort_by_key(|f| f.tag);
87        len += tagged_fields_len(&all_tags)?;
88        Ok(len)
89    }
90}