Skip to main content

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

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