Skip to main content

krabka_protocol/opt/rustwide/workdir/generated/
RemoveRaftVoterRequest.borrowed.rs

1// AUTO-GENERATED by krabka-protocol-codegen against a9ce3221537b8653448750697915607dc7936cf3. Do not edit.
2use bytes::BufMut;
3
4use crate::{
5    DecodeBorrow, Encode, ProtocolError, UnknownTaggedFields,
6    primitives::{
7        fixed::{get_i32, put_i32},
8        string_bytes::{
9            compact_nullable_string_len, nullable_string_len, put_compact_nullable_string,
10            put_nullable_string,
11        },
12        string_bytes_borrowed::{
13            get_compact_nullable_string_borrowed, get_nullable_string_borrowed,
14        },
15    },
16    tagged_fields::{WriteTaggedFields, read_tagged_fields, tagged_fields_len},
17};
18pub const API_KEY: i16 = 81;
19pub const MIN_VERSION: i16 = 0;
20pub const MAX_VERSION: i16 = 0;
21pub const LATEST_STABLE_VERSION: i16 = 0;
22pub const FLEXIBLE_MIN: i16 = 0;
23#[inline]
24#[must_use]
25pub fn is_flexible(version: i16) -> bool {
26    version >= FLEXIBLE_MIN
27}
28#[derive(Debug, Clone, PartialEq, Eq)]
29pub struct RemoveRaftVoterRequest<'a> {
30    pub cluster_id: Option<&'a str>,
31    pub voter_id: i32,
32    pub voter_directory_id: crate::primitives::uuid::Uuid,
33    pub unknown_tagged_fields: UnknownTaggedFields,
34}
35impl Default for RemoveRaftVoterRequest<'_> {
36    fn default() -> Self {
37        Self {
38            cluster_id: Some(""),
39            voter_id: 0i32,
40            voter_directory_id: crate::primitives::uuid::Uuid::default(),
41            unknown_tagged_fields: UnknownTaggedFields::default(),
42        }
43    }
44}
45impl RemoveRaftVoterRequest<'_> {
46    /// # Panics
47    ///
48    /// Panics if a records field contains an invalid encoded record batch.
49    #[must_use]
50    pub fn to_owned(&self) -> crate::owned::remove_raft_voter_request::RemoveRaftVoterRequest {
51        crate::owned::remove_raft_voter_request::RemoveRaftVoterRequest {
52            cluster_id: (self.cluster_id).map(std::string::ToString::to_string),
53            voter_id: (self.voter_id),
54            voter_directory_id: (self.voter_directory_id),
55            unknown_tagged_fields: self.unknown_tagged_fields.clone(),
56        }
57    }
58}
59impl Encode for RemoveRaftVoterRequest<'_> {
60    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
61        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
62            return Err(ProtocolError::UnsupportedVersion {
63                api_key: API_KEY,
64                version,
65            });
66        }
67        let flex = is_flexible(version);
68        if version >= 0 {
69            if flex {
70                let () = put_compact_nullable_string(buf, self.cluster_id);
71            } else {
72                let () = put_nullable_string(buf, self.cluster_id);
73            }
74        }
75        if version >= 0 {
76            put_i32(buf, self.voter_id);
77        }
78        if version >= 0 {
79            crate::primitives::uuid::put_uuid(buf, self.voter_directory_id);
80        }
81        if flex {
82            let tagged = WriteTaggedFields::new();
83            tagged.write(buf, &self.unknown_tagged_fields);
84        }
85        Ok(())
86    }
87    fn encoded_len(&self, version: i16) -> usize {
88        let flex = is_flexible(version);
89        let mut n: usize = 0;
90        if version >= 0 {
91            n += if flex {
92                compact_nullable_string_len(self.cluster_id)
93            } else {
94                nullable_string_len(self.cluster_id)
95            };
96        }
97        if version >= 0 {
98            n += 4;
99        }
100        if version >= 0 {
101            n += 16;
102        }
103        if flex {
104            let known_pairs: Vec<(u32, usize)> = Vec::new();
105            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
106        }
107        n
108    }
109}
110impl<'de> DecodeBorrow<'de> for RemoveRaftVoterRequest<'de> {
111    fn decode_borrow(buf: &mut &'de [u8], version: i16) -> Result<Self, ProtocolError> {
112        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
113            return Err(ProtocolError::UnsupportedVersion {
114                api_key: API_KEY,
115                version,
116            });
117        }
118        let flex = is_flexible(version);
119        let mut out = Self::default();
120        if version >= 0 {
121            out.cluster_id = if flex {
122                get_compact_nullable_string_borrowed(buf)?
123            } else {
124                get_nullable_string_borrowed(buf)?
125            };
126        }
127        if version >= 0 {
128            out.voter_id = get_i32(buf)?;
129        }
130        if version >= 0 {
131            out.voter_directory_id = crate::primitives::uuid::get_uuid(buf)?;
132        }
133        if flex {
134            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
135        }
136        Ok(out)
137    }
138}
139#[cfg(test)]
140impl RemoveRaftVoterRequest<'_> {
141    #[must_use]
142    pub fn populated(version: i16) -> Self {
143        let mut m = Self::default();
144        if version >= 0 {
145            m.cluster_id = Some("x");
146        }
147        if version >= 0 {
148            m.voter_id = 1i32;
149        }
150        if version >= 0 {
151            m.voter_directory_id = crate::primitives::uuid::Uuid([1u8; 16]);
152        }
153        m
154    }
155}