crabka_protocol/opt/rustwide/workdir/generated/
AddRaftVoterResponse.borrowed.rs1use bytes::BufMut;
4
5use crate::primitives::fixed::{get_i16, get_i32, put_i16, put_i32};
6use crate::primitives::string_bytes::{
7 compact_nullable_string_len, compact_string_len, nullable_string_len,
8 put_compact_nullable_string, put_compact_string, put_nullable_string, put_string,
9 string_len,
10};
11use crate::primitives::string_bytes_borrowed::{
12 get_compact_nullable_string_borrowed, get_compact_string_borrowed,
13 get_nullable_string_borrowed, get_string_borrowed,
14};
15use crate::tagged_fields::{read_tagged_fields, tagged_fields_len, WriteTaggedFields};
16use crate::{DecodeBorrow, Encode, ProtocolError, UnknownTaggedFields};
17
18pub const API_KEY: i16 = 80;
19pub const MIN_VERSION: i16 = 0;
20pub const MAX_VERSION: i16 = 1;
21pub const FLEXIBLE_MIN: i16 = 0;
22
23#[inline]
24fn is_flexible(version: i16) -> bool { version >= FLEXIBLE_MIN }
25
26#[derive(Debug, Clone, PartialEq, Eq)]
27pub struct AddRaftVoterResponse<'a> {
28 pub throttle_time_ms: i32,
29 pub error_code: i16,
30 pub error_message: Option<&'a str>,
31 pub unknown_tagged_fields: UnknownTaggedFields,
32}
33
34impl<'a> Default for AddRaftVoterResponse<'a> {
35 fn default() -> Self {
36 Self {
37 throttle_time_ms: 0i32,
38 error_code: 0i16,
39 error_message: None,
40 unknown_tagged_fields: Default::default(),
41 }
42 }
43}
44
45impl<'a> AddRaftVoterResponse<'a> {
46 pub fn to_owned(&self) -> crate::owned::add_raft_voter_response::AddRaftVoterResponse {
47 crate::owned::add_raft_voter_response::AddRaftVoterResponse {
48 throttle_time_ms: (self.throttle_time_ms),
49 error_code: (self.error_code),
50 error_message: (self.error_message).map(|s| s.to_string()),
51 unknown_tagged_fields: self.unknown_tagged_fields.clone(),
52 }
53 }
54}
55
56impl<'a> Encode for AddRaftVoterResponse<'a> {
57 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
58 if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
59 return Err(ProtocolError::UnsupportedVersion { api_key: API_KEY, version });
60 }
61 let flex = is_flexible(version);
62 if version >= 0 { put_i32(buf, self.throttle_time_ms) }
63 if version >= 0 { put_i16(buf, self.error_code) }
64 if version >= 0 { if flex { put_compact_nullable_string(buf, self.error_message) } else { put_nullable_string(buf, self.error_message) } }
65 if flex {
66 let tagged = WriteTaggedFields::new();
67 tagged.write(buf, &self.unknown_tagged_fields);
68 }
69 Ok(())
70 }
71 fn encoded_len(&self, version: i16) -> usize {
72 let flex = is_flexible(version);
73 let mut n: usize = 0;
74 if version >= 0 { n += 4; }
75 if version >= 0 { n += 2; }
76 if version >= 0 { n += if flex { compact_nullable_string_len(self.error_message) } else { nullable_string_len(self.error_message) }; }
77 if flex {
78 let known_pairs: Vec<(u32, usize)> = Vec::new();
79 n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
80 }
81 n
82 }
83}
84
85impl<'de> DecodeBorrow<'de> for AddRaftVoterResponse<'de> {
86 fn decode_borrow(buf: &mut &'de [u8], version: i16) -> Result<Self, ProtocolError> {
87 if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
88 return Err(ProtocolError::UnsupportedVersion { api_key: API_KEY, version });
89 }
90 let flex = is_flexible(version);
91 let mut out = Self::default();
92 if version >= 0 { out.throttle_time_ms = get_i32(buf)?; }
93 if version >= 0 { out.error_code = get_i16(buf)?; }
94 if version >= 0 { out.error_message = if flex { get_compact_nullable_string_borrowed(buf)? } else { get_nullable_string_borrowed(buf)? }; }
95 if flex {
96 out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| {
97 Ok(false)
98 })?;
99 }
100 Ok(out)
101 }
102}