Skip to main content

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

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