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