Skip to main content

kacrab_protocol/generated/
envelope_request.rs

1//! Generated from EnvelopeRequest.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 EnvelopeRequestData {
17    /// The embedded request header and data.
18    pub request_data: Bytes,
19    /// Value of the initial client principal when the request is redirected by a broker.
20    pub request_principal: Option<Bytes>,
21    /// The original client's address in bytes.
22    pub client_host_address: Bytes,
23    pub _unknown_tagged_fields: Vec<RawTaggedField>,
24}
25impl Default for EnvelopeRequestData {
26    fn default() -> Self {
27        Self {
28            request_data: Bytes::new(),
29            request_principal: None,
30            client_host_address: Bytes::new(),
31            _unknown_tagged_fields: Vec::new(),
32        }
33    }
34}
35impl EnvelopeRequestData {
36    pub fn with_request_data(mut self, value: Bytes) -> Self {
37        self.request_data = value;
38        self
39    }
40    pub fn with_request_principal(mut self, value: Option<Bytes>) -> Self {
41        self.request_principal = value;
42        self
43    }
44    pub fn with_client_host_address(mut self, value: Bytes) -> Self {
45        self.client_host_address = value;
46        self
47    }
48    pub fn read(buf: &mut Bytes, version: i16) -> Result<Self> {
49        if version < 0 || version > 0 {
50            return Err(UnsupportedVersion::new(58, version).into());
51        }
52        let request_data;
53        let request_principal;
54        let client_host_address;
55        let mut _unknown_tagged_fields: Vec<RawTaggedField> = Vec::new();
56        request_data = read_compact_bytes(buf)?;
57        request_principal = read_compact_nullable_bytes(buf)?;
58        client_host_address = read_compact_bytes(buf)?;
59        let tagged_fields = read_tagged_fields(buf)?;
60        for field in &tagged_fields {
61            match field.tag {
62                _ => {
63                    _unknown_tagged_fields.push(field.clone());
64                },
65            }
66        }
67        Ok(Self {
68            request_data,
69            request_principal,
70            client_host_address,
71            _unknown_tagged_fields,
72        })
73    }
74    pub fn write(&self, buf: &mut BytesMut, version: i16) -> Result<()> {
75        if version < 0 || version > 0 {
76            return Err(UnsupportedVersion::new(58, version).into());
77        }
78        write_compact_bytes(buf, &self.request_data)?;
79        write_compact_nullable_bytes(buf, self.request_principal.as_ref().map(|b| b.as_ref()))?;
80        write_compact_bytes(buf, &self.client_host_address)?;
81        let mut all_tags: Vec<RawTaggedField> = self._unknown_tagged_fields.clone();
82        all_tags.sort_by_key(|f| f.tag);
83        write_tagged_fields(buf, &all_tags)?;
84        Ok(())
85    }
86    pub fn encoded_len(&self, version: i16) -> Result<usize> {
87        if version < 0 || version > 0 {
88            return Err(UnsupportedVersion::new(58, version).into());
89        }
90        let mut len: usize = 0;
91        len += compact_bytes_len(&self.request_data)?;
92        len += compact_nullable_bytes_len(self.request_principal.as_ref().map(|b| b.as_ref()))?;
93        len += compact_bytes_len(&self.client_host_address)?;
94        let mut all_tags: Vec<RawTaggedField> = self._unknown_tagged_fields.clone();
95        all_tags.sort_by_key(|f| f.tag);
96        len += tagged_fields_len(&all_tags)?;
97        Ok(len)
98    }
99}