crabka_protocol/opt/rustwide/workdir/generated/
RemoveRaftVoterRequest.owned.rs1use bytes::{Buf, BufMut};
4
5use crate::primitives::fixed::{get_i32, put_i32};
6use crate::primitives::string_bytes::{
7 compact_nullable_string_len, compact_string_len, get_compact_nullable_string_owned,
8 get_compact_string_owned, get_nullable_string_owned, get_string_owned, nullable_string_len,
9 put_compact_nullable_string, put_compact_string, put_nullable_string, put_string,
10 string_len,
11};
12use crate::tagged_fields::{read_tagged_fields, tagged_fields_len, WriteTaggedFields};
13use crate::{Decode, Encode, ProtocolError, UnknownTaggedFields};
14
15pub const API_KEY: i16 = 81;
16pub const MIN_VERSION: i16 = 0;
17pub const MAX_VERSION: i16 = 0;
18pub const FLEXIBLE_MIN: i16 = 0;
19
20#[inline]
21fn is_flexible(version: i16) -> bool { version >= FLEXIBLE_MIN }
22
23#[derive(Debug, Clone, PartialEq, Eq, Default)]
24pub struct RemoveRaftVoterRequest {
25 pub cluster_id: Option<String>,
26 pub voter_id: i32,
27 pub voter_directory_id: crate::primitives::uuid::Uuid,
28 pub unknown_tagged_fields: UnknownTaggedFields,
29}
30
31impl Encode for RemoveRaftVoterRequest {
32 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
33 if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
34 return Err(ProtocolError::UnsupportedVersion { api_key: API_KEY, version });
35 }
36 let flex = is_flexible(version);
37 if version >= 0 { if flex { put_compact_nullable_string(buf, self.cluster_id.as_deref()) } else { put_nullable_string(buf, self.cluster_id.as_deref()) } }
38 if version >= 0 { put_i32(buf, self.voter_id) }
39 if version >= 0 { crate::primitives::uuid::put_uuid(buf, self.voter_directory_id) }
40 if flex {
41 let tagged = WriteTaggedFields::new();
42 tagged.write(buf, &self.unknown_tagged_fields);
43 }
44 Ok(())
45 }
46 fn encoded_len(&self, version: i16) -> usize {
47 let flex = is_flexible(version);
48 let mut n: usize = 0;
49 if version >= 0 { n += if flex { compact_nullable_string_len(self.cluster_id.as_deref()) } else { nullable_string_len(self.cluster_id.as_deref()) }; }
50 if version >= 0 { n += 4; }
51 if version >= 0 { n += 16; }
52 if flex {
53 let known_pairs: Vec<(u32, usize)> = Vec::new();
54 n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
55 }
56 n
57 }
58}
59
60impl<'de> Decode<'de> for RemoveRaftVoterRequest {
61 fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
62 if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
63 return Err(ProtocolError::UnsupportedVersion { api_key: API_KEY, version });
64 }
65 let flex = is_flexible(version);
66 let mut out = Self::default();
67 if version >= 0 { out.cluster_id = if flex { get_compact_nullable_string_owned(buf)? } else { get_nullable_string_owned(buf)? }; }
68 if version >= 0 { out.voter_id = get_i32(buf)?; }
69 if version >= 0 { out.voter_directory_id = crate::primitives::uuid::get_uuid(buf)?; }
70 if flex {
71 out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| {
72 Ok(false)
73 })?;
74 }
75 Ok(out)
76 }
77}
78
79#[must_use]
82#[allow(unused_comparisons)]
83pub fn default_json(version: i16) -> ::serde_json::Value {
84 let mut obj = ::serde_json::Map::new();
85 obj.insert("clusterId".to_string(), ::serde_json::Value::Null);
86 obj.insert("voterId".to_string(), ::serde_json::json!(0));
87 obj.insert("voterDirectoryId".to_string(), ::serde_json::Value::String("AAAAAAAAAAAAAAAAAAAAAA".to_string()));
88 ::serde_json::Value::Object(obj)
89}
90
91impl crate::ProtocolRequest for RemoveRaftVoterRequest {
92 const API_KEY: i16 = API_KEY;
93 const MIN_VERSION: i16 = MIN_VERSION;
94 const MAX_VERSION: i16 = MAX_VERSION;
95 const FLEXIBLE_MIN: i16 = FLEXIBLE_MIN;
96 type Response = super::remove_raft_voter_response::RemoveRaftVoterResponse;
97}