Skip to main content

crabka_protocol/opt/rustwide/workdir/generated/
CreateAclsResponse.borrowed.rs

1// AUTO-GENERATED by crabka-protocol-codegen against a9ce3221537b8653448750697915607dc7936cf3. Do not edit.
2
3use 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 = 30;
19pub const MIN_VERSION: i16 = 1;
20pub const MAX_VERSION: i16 = 3;
21pub const FLEXIBLE_MIN: i16 = 2;
22
23#[inline]
24fn is_flexible(version: i16) -> bool { version >= FLEXIBLE_MIN }
25
26#[derive(Debug, Clone, PartialEq, Eq)]
27pub struct CreateAclsResponse<'a> {
28    pub throttle_time_ms: i32,
29    pub results: Vec<AclCreationResult<'a>>,
30    pub unknown_tagged_fields: UnknownTaggedFields,
31}
32
33impl<'a> Default for CreateAclsResponse<'a> {
34    fn default() -> Self {
35        Self {
36            throttle_time_ms: 0i32,
37            results: Vec::new(),
38            unknown_tagged_fields: Default::default(),
39        }
40    }
41}
42
43impl<'a> CreateAclsResponse<'a> {
44    pub fn to_owned(&self) -> crate::owned::create_acls_response::CreateAclsResponse {
45        crate::owned::create_acls_response::CreateAclsResponse {
46            throttle_time_ms: (self.throttle_time_ms),
47            results: (self.results).iter().map(|it| it.to_owned()).collect(),
48            unknown_tagged_fields: self.unknown_tagged_fields.clone(),
49        }
50    }
51}
52
53impl<'a> Encode for CreateAclsResponse<'a> {
54    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
55        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
56            return Err(ProtocolError::UnsupportedVersion { api_key: API_KEY, version });
57        }
58        let flex = is_flexible(version);
59        if version >= 0 { put_i32(buf, self.throttle_time_ms) }
60        if version >= 0 { { crate::primitives::array::put_array_len(buf, (self.results).len(), flex); for it in &self.results { it.encode(buf, version)?; } } }
61        if flex {
62            let tagged = WriteTaggedFields::new();
63            tagged.write(buf, &self.unknown_tagged_fields);
64        }
65        Ok(())
66    }
67    fn encoded_len(&self, version: i16) -> usize {
68        let flex = is_flexible(version);
69        let mut n: usize = 0;
70        if version >= 0 { n += 4; }
71        if version >= 0 { n += { let prefix = crate::primitives::array::array_len_prefix_len((self.results).len(), flex); let body: usize = (self.results).iter().map(|it| it.encoded_len(version)).sum(); prefix + body }; }
72        if flex {
73            let known_pairs: Vec<(u32, usize)> = Vec::new();
74            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
75        }
76        n
77    }
78}
79
80impl<'de> DecodeBorrow<'de> for CreateAclsResponse<'de> {
81    fn decode_borrow(buf: &mut &'de [u8], version: i16) -> Result<Self, ProtocolError> {
82        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
83            return Err(ProtocolError::UnsupportedVersion { api_key: API_KEY, version });
84        }
85        let flex = is_flexible(version);
86        let mut out = Self::default();
87        if version >= 0 { out.throttle_time_ms = get_i32(buf)?; }
88        if version >= 0 { out.results = { let n = crate::primitives::array::get_array_len(buf, flex)?; let mut v = Vec::with_capacity(n); for _ in 0..n { v.push(AclCreationResult::decode_borrow(buf, version)?); } v }; }
89        if flex {
90            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| {
91                Ok(false)
92            })?;
93        }
94        Ok(out)
95    }
96}
97
98#[derive(Debug, Clone, PartialEq, Eq)]
99pub struct AclCreationResult<'a> {
100    pub error_code: i16,
101    pub error_message: Option<&'a str>,
102    pub unknown_tagged_fields: UnknownTaggedFields,
103}
104
105impl<'a> Default for AclCreationResult<'a> {
106    fn default() -> Self {
107        Self {
108            error_code: 0i16,
109            error_message: None,
110            unknown_tagged_fields: Default::default(),
111        }
112    }
113}
114
115impl<'a> AclCreationResult<'a> {
116    pub fn to_owned(&self) -> crate::owned::create_acls_response::AclCreationResult {
117        crate::owned::create_acls_response::AclCreationResult {
118            error_code: (self.error_code),
119            error_message: (self.error_message).map(|s| s.to_string()),
120            unknown_tagged_fields: self.unknown_tagged_fields.clone(),
121        }
122    }
123}
124
125impl<'a> Encode for AclCreationResult<'a> {
126    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
127        let flex = version >= 2;
128        if version >= 0 { put_i16(buf, self.error_code) }
129        if version >= 0 { if flex { put_compact_nullable_string(buf, self.error_message) } else { put_nullable_string(buf, self.error_message) } }
130        if flex {
131            let tagged = WriteTaggedFields::new();
132            tagged.write(buf, &self.unknown_tagged_fields);
133        }
134        Ok(())
135    }
136    fn encoded_len(&self, version: i16) -> usize {
137        let flex = version >= 2;
138        let mut n: usize = 0;
139        if version >= 0 { n += 2; }
140        if version >= 0 { n += if flex { compact_nullable_string_len(self.error_message) } else { nullable_string_len(self.error_message) }; }
141        if flex {
142            let known_pairs: Vec<(u32, usize)> = Vec::new();
143            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
144        }
145        n
146    }
147}
148
149impl<'de> DecodeBorrow<'de> for AclCreationResult<'de> {
150    fn decode_borrow(buf: &mut &'de [u8], version: i16) -> Result<Self, ProtocolError> {
151        let flex = version >= 2;
152        let mut out = Self::default();
153        if version >= 0 { out.error_code = get_i16(buf)?; }
154        if version >= 0 { out.error_message = if flex { get_compact_nullable_string_borrowed(buf)? } else { get_nullable_string_borrowed(buf)? }; }
155        if flex {
156            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| {
157                Ok(false)
158            })?;
159        }
160        Ok(out)
161    }
162}