krabka_protocol/opt/rustwide/workdir/generated/
RemoveRaftVoterRequest.owned.rs1use bytes::{Buf, BufMut};
4
5use crate::{
6 Decode, Encode, ProtocolError, UnknownTaggedFields,
7 primitives::{
8 fixed::{get_i32, put_i32},
9 string_bytes::{
10 compact_nullable_string_len, get_compact_nullable_string_owned,
11 get_nullable_string_owned, nullable_string_len, put_compact_nullable_string,
12 put_nullable_string,
13 },
14 uuid::{Uuid, get_uuid, put_uuid},
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 {
30 pub cluster_id: Option<String>,
31 pub voter_id: i32,
32 pub voter_directory_id: Uuid,
33 pub unknown_tagged_fields: UnknownTaggedFields,
34}
35impl Default for RemoveRaftVoterRequest {
36 fn default() -> Self {
37 Self {
38 cluster_id: Some(String::new()),
39 voter_id: 0i32,
40 voter_directory_id: Uuid::default(),
41 unknown_tagged_fields: UnknownTaggedFields::default(),
42 }
43 }
44}
45impl Encode for RemoveRaftVoterRequest {
46 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
47 if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
48 return Err(ProtocolError::UnsupportedVersion {
49 api_key: API_KEY,
50 version,
51 });
52 }
53 let flex = is_flexible(version);
54 if version >= 0 {
55 if flex {
56 put_compact_nullable_string(buf, self.cluster_id.as_deref())?;
57 } else {
58 put_nullable_string(buf, self.cluster_id.as_deref())?;
59 }
60 }
61 if version >= 0 {
62 put_i32(buf, self.voter_id);
63 }
64 if version >= 0 {
65 put_uuid(buf, self.voter_directory_id);
66 }
67 if flex {
68 let tagged = WriteTaggedFields::new();
69 tagged.write(buf, &self.unknown_tagged_fields)?;
70 }
71 Ok(())
72 }
73 fn encoded_len(&self, version: i16) -> usize {
74 let flex = is_flexible(version);
75 let mut n: usize = 0;
76 if version >= 0 {
77 n += if flex {
78 compact_nullable_string_len(self.cluster_id.as_deref())
79 } else {
80 nullable_string_len(self.cluster_id.as_deref())
81 };
82 }
83 if version >= 0 {
84 n += 4;
85 }
86 if version >= 0 {
87 n += 16;
88 }
89 if flex {
90 let known_pairs: Vec<(u32, usize)> = Vec::new();
91 n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
92 }
93 n
94 }
95}
96impl Decode<'_> for RemoveRaftVoterRequest {
97 fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
98 if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
99 return Err(ProtocolError::UnsupportedVersion {
100 api_key: API_KEY,
101 version,
102 });
103 }
104 let flex = is_flexible(version);
105 let mut out = Self::default();
106 if version >= 0 {
107 out.cluster_id = if flex {
108 get_compact_nullable_string_owned(buf)?
109 } else {
110 get_nullable_string_owned(buf)?
111 };
112 }
113 if version >= 0 {
114 out.voter_id = get_i32(buf)?;
115 }
116 if version >= 0 {
117 out.voter_directory_id = get_uuid(buf)?;
118 }
119 if flex {
120 out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
121 }
122 Ok(out)
123 }
124}
125#[cfg(test)]
126impl RemoveRaftVoterRequest {
127 #[must_use]
128 pub fn populated(version: i16) -> Self {
129 let mut m = Self::default();
130 if version >= 0 {
131 m.cluster_id = Some("x".to_owned());
132 }
133 if version >= 0 {
134 m.voter_id = 1i32;
135 }
136 if version >= 0 {
137 m.voter_directory_id = Uuid([1u8; 16]);
138 }
139 m
140 }
141}
142#[must_use]
145#[allow(unused_comparisons)]
146pub fn default_json(_version: i16) -> ::serde_json::Value {
147 let mut obj = ::serde_json::Map::new();
148 obj.insert(
149 "clusterId".to_owned(),
150 ::serde_json::Value::String(String::new()),
151 );
152 obj.insert("voterId".to_owned(), ::serde_json::json!(0));
153 obj.insert(
154 "voterDirectoryId".to_owned(),
155 ::serde_json::Value::String("AAAAAAAAAAAAAAAAAAAAAA".to_owned()),
156 );
157 ::serde_json::Value::Object(obj)
158}
159impl crate::ProtocolRequest for RemoveRaftVoterRequest {
160 const API_KEY: i16 = API_KEY;
161 const MIN_VERSION: i16 = MIN_VERSION;
162 const MAX_VERSION: i16 = MAX_VERSION;
163 const LATEST_STABLE_VERSION: i16 = LATEST_STABLE_VERSION;
164 const FLEXIBLE_MIN: i16 = FLEXIBLE_MIN;
165 type Response = super::remove_raft_voter_response::RemoveRaftVoterResponse;
166}