Skip to main content

krabka_protocol/opt/rustwide/workdir/generated/
RemoveRaftVoterRequest.owned.rs

1// AUTO-GENERATED by krabka-protocol-codegen against a9ce3221537b8653448750697915607dc7936cf3. Do not edit.
2
3use 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    },
15    tagged_fields::{WriteTaggedFields, read_tagged_fields, tagged_fields_len},
16};
17pub const API_KEY: i16 = 81;
18pub const MIN_VERSION: i16 = 0;
19pub const MAX_VERSION: i16 = 0;
20pub const LATEST_STABLE_VERSION: i16 = 0;
21pub const FLEXIBLE_MIN: i16 = 0;
22#[inline]
23#[must_use]
24pub fn is_flexible(version: i16) -> bool {
25    version >= FLEXIBLE_MIN
26}
27#[derive(Debug, Clone, PartialEq, Eq)]
28pub struct RemoveRaftVoterRequest {
29    pub cluster_id: Option<String>,
30    pub voter_id: i32,
31    pub voter_directory_id: crate::primitives::uuid::Uuid,
32    pub unknown_tagged_fields: UnknownTaggedFields,
33}
34impl Default for RemoveRaftVoterRequest {
35    fn default() -> Self {
36        Self {
37            cluster_id: Some(String::new()),
38            voter_id: 0i32,
39            voter_directory_id: crate::primitives::uuid::Uuid::default(),
40            unknown_tagged_fields: UnknownTaggedFields::default(),
41        }
42    }
43}
44impl Encode for RemoveRaftVoterRequest {
45    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
46        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
47            return Err(ProtocolError::UnsupportedVersion {
48                api_key: API_KEY,
49                version,
50            });
51        }
52        let flex = is_flexible(version);
53        if version >= 0 {
54            if flex {
55                let () = put_compact_nullable_string(buf, self.cluster_id.as_deref());
56            } else {
57                let () = put_nullable_string(buf, self.cluster_id.as_deref());
58            }
59        }
60        if version >= 0 {
61            put_i32(buf, self.voter_id);
62        }
63        if version >= 0 {
64            crate::primitives::uuid::put_uuid(buf, self.voter_directory_id);
65        }
66        if flex {
67            let tagged = WriteTaggedFields::new();
68            tagged.write(buf, &self.unknown_tagged_fields);
69        }
70        Ok(())
71    }
72    fn encoded_len(&self, version: i16) -> usize {
73        let flex = is_flexible(version);
74        let mut n: usize = 0;
75        if version >= 0 {
76            n += if flex {
77                compact_nullable_string_len(self.cluster_id.as_deref())
78            } else {
79                nullable_string_len(self.cluster_id.as_deref())
80            };
81        }
82        if version >= 0 {
83            n += 4;
84        }
85        if version >= 0 {
86            n += 16;
87        }
88        if flex {
89            let known_pairs: Vec<(u32, usize)> = Vec::new();
90            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
91        }
92        n
93    }
94}
95impl Decode<'_> for RemoveRaftVoterRequest {
96    fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
97        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
98            return Err(ProtocolError::UnsupportedVersion {
99                api_key: API_KEY,
100                version,
101            });
102        }
103        let flex = is_flexible(version);
104        let mut out = Self::default();
105        if version >= 0 {
106            out.cluster_id = if flex {
107                get_compact_nullable_string_owned(buf)?
108            } else {
109                get_nullable_string_owned(buf)?
110            };
111        }
112        if version >= 0 {
113            out.voter_id = get_i32(buf)?;
114        }
115        if version >= 0 {
116            out.voter_directory_id = crate::primitives::uuid::get_uuid(buf)?;
117        }
118        if flex {
119            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
120        }
121        Ok(out)
122    }
123}
124#[cfg(test)]
125impl RemoveRaftVoterRequest {
126    #[must_use]
127    pub fn populated(version: i16) -> Self {
128        let mut m = Self::default();
129        if version >= 0 {
130            m.cluster_id = Some("x".to_string());
131        }
132        if version >= 0 {
133            m.voter_id = 1i32;
134        }
135        if version >= 0 {
136            m.voter_directory_id = crate::primitives::uuid::Uuid([1u8; 16]);
137        }
138        m
139    }
140}
141/// Default JSON payload matching `Self::default()` for JVM oracle differential testing.
142/// Only includes fields valid for the given version.
143#[must_use]
144#[allow(unused_comparisons)]
145pub fn default_json(_version: i16) -> ::serde_json::Value {
146    let mut obj = ::serde_json::Map::new();
147    obj.insert(
148        "clusterId".to_string(),
149        ::serde_json::Value::String(String::new()),
150    );
151    obj.insert("voterId".to_string(), ::serde_json::json!(0));
152    obj.insert(
153        "voterDirectoryId".to_string(),
154        ::serde_json::Value::String("AAAAAAAAAAAAAAAAAAAAAA".to_string()),
155    );
156    ::serde_json::Value::Object(obj)
157}
158impl crate::ProtocolRequest for RemoveRaftVoterRequest {
159    const API_KEY: i16 = API_KEY;
160    const MIN_VERSION: i16 = MIN_VERSION;
161    const MAX_VERSION: i16 = MAX_VERSION;
162    const LATEST_STABLE_VERSION: i16 = LATEST_STABLE_VERSION;
163    const FLEXIBLE_MIN: i16 = FLEXIBLE_MIN;
164    type Response = super::remove_raft_voter_response::RemoveRaftVoterResponse;
165}