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