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, compact_string_len, nullable_string_len,
8    put_compact_nullable_string, put_compact_string, put_nullable_string, put_string,
9    string_len,
10};
11use crate::primitives::string_bytes_borrowed::{
12    get_compact_nullable_string_borrowed, get_compact_string_borrowed,
13    get_nullable_string_borrowed, get_string_borrowed,
14};
15use crate::tagged_fields::{read_tagged_fields, tagged_fields_len, WriteTaggedFields};
16use crate::{DecodeBorrow, Encode, ProtocolError, UnknownTaggedFields};
17
18pub const API_KEY: i16 = 81;
19pub const MIN_VERSION: i16 = 0;
20pub const MAX_VERSION: i16 = 0;
21pub const FLEXIBLE_MIN: i16 = 0;
22
23#[inline]
24fn is_flexible(version: i16) -> bool { version >= FLEXIBLE_MIN }
25
26#[derive(Debug, Clone, PartialEq, Eq)]
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}
33
34impl<'a> Default for RemoveRaftVoterRequest<'a> {
35    fn default() -> Self {
36        Self {
37            cluster_id: None,
38            voter_id: 0i32,
39            voter_directory_id: Default::default(),
40            unknown_tagged_fields: Default::default(),
41        }
42    }
43}
44
45impl<'a> RemoveRaftVoterRequest<'a> {
46    pub fn to_owned(&self) -> crate::owned::remove_raft_voter_request::RemoveRaftVoterRequest {
47        crate::owned::remove_raft_voter_request::RemoveRaftVoterRequest {
48            cluster_id: (self.cluster_id).map(|s| s.to_string()),
49            voter_id: (self.voter_id),
50            voter_directory_id: (self.voter_directory_id),
51            unknown_tagged_fields: self.unknown_tagged_fields.clone(),
52        }
53    }
54}
55
56impl<'a> Encode for RemoveRaftVoterRequest<'a> {
57    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
58        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
59            return Err(ProtocolError::UnsupportedVersion { api_key: API_KEY, version });
60        }
61        let flex = is_flexible(version);
62        if version >= 0 { if flex { put_compact_nullable_string(buf, self.cluster_id) } else { put_nullable_string(buf, self.cluster_id) } }
63        if version >= 0 { put_i32(buf, self.voter_id) }
64        if version >= 0 { crate::primitives::uuid::put_uuid(buf, self.voter_directory_id) }
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 { n += if flex { compact_nullable_string_len(self.cluster_id) } else { nullable_string_len(self.cluster_id) }; }
75        if version >= 0 { n += 4; }
76        if version >= 0 { n += 16; }
77        if flex {
78            let known_pairs: Vec<(u32, usize)> = Vec::new();
79            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
80        }
81        n
82    }
83}
84
85impl<'de> DecodeBorrow<'de> for RemoveRaftVoterRequest<'de> {
86    fn decode_borrow(buf: &mut &'de [u8], version: i16) -> Result<Self, ProtocolError> {
87        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
88            return Err(ProtocolError::UnsupportedVersion { api_key: API_KEY, version });
89        }
90        let flex = is_flexible(version);
91        let mut out = Self::default();
92        if version >= 0 { out.cluster_id = if flex { get_compact_nullable_string_borrowed(buf)? } else { get_nullable_string_borrowed(buf)? }; }
93        if version >= 0 { out.voter_id = get_i32(buf)?; }
94        if version >= 0 { out.voter_directory_id = crate::primitives::uuid::get_uuid(buf)?; }
95        if flex {
96            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| {
97                Ok(false)
98            })?;
99        }
100        Ok(out)
101    }
102}