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