crabka_protocol/opt/rustwide/workdir/generated/
DescribeClientQuotasRequest.borrowed.rs1use bytes::BufMut;
4
5use crate::primitives::fixed::{get_bool, get_i8, put_bool, put_i8};
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 = 48;
19pub const MIN_VERSION: i16 = 0;
20pub const MAX_VERSION: i16 = 1;
21pub const FLEXIBLE_MIN: i16 = 1;
22
23#[inline]
24fn is_flexible(version: i16) -> bool { version >= FLEXIBLE_MIN }
25
26#[derive(Debug, Clone, PartialEq, Eq)]
27pub struct DescribeClientQuotasRequest<'a> {
28 pub components: Vec<ComponentData<'a>>,
29 pub strict: bool,
30 pub unknown_tagged_fields: UnknownTaggedFields,
31}
32
33impl<'a> Default for DescribeClientQuotasRequest<'a> {
34 fn default() -> Self {
35 Self {
36 components: Vec::new(),
37 strict: false,
38 unknown_tagged_fields: Default::default(),
39 }
40 }
41}
42
43impl<'a> DescribeClientQuotasRequest<'a> {
44 pub fn to_owned(&self) -> crate::owned::describe_client_quotas_request::DescribeClientQuotasRequest {
45 crate::owned::describe_client_quotas_request::DescribeClientQuotasRequest {
46 components: (self.components).iter().map(|it| it.to_owned()).collect(),
47 strict: (self.strict),
48 unknown_tagged_fields: self.unknown_tagged_fields.clone(),
49 }
50 }
51}
52
53impl<'a> Encode for DescribeClientQuotasRequest<'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 { { crate::primitives::array::put_array_len(buf, (self.components).len(), flex); for it in &self.components { it.encode(buf, version)?; } } }
60 if version >= 0 { put_bool(buf, self.strict) }
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 += { let prefix = crate::primitives::array::array_len_prefix_len((self.components).len(), flex); let body: usize = (self.components).iter().map(|it| it.encoded_len(version)).sum(); prefix + body }; }
71 if version >= 0 { n += 1; }
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 DescribeClientQuotasRequest<'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.components = { let n = crate::primitives::array::get_array_len(buf, flex)?; let mut v = Vec::with_capacity(n); for _ in 0..n { v.push(ComponentData::decode_borrow(buf, version)?); } v }; }
88 if version >= 0 { out.strict = get_bool(buf)?; }
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 ComponentData<'a> {
100 pub entity_type: &'a str,
101 pub match_type: i8,
102 pub match_: Option<&'a str>,
103 pub unknown_tagged_fields: UnknownTaggedFields,
104}
105
106impl<'a> Default for ComponentData<'a> {
107 fn default() -> Self {
108 Self {
109 entity_type: "",
110 match_type: 0i8,
111 match_: None,
112 unknown_tagged_fields: Default::default(),
113 }
114 }
115}
116
117impl<'a> ComponentData<'a> {
118 pub fn to_owned(&self) -> crate::owned::describe_client_quotas_request::ComponentData {
119 crate::owned::describe_client_quotas_request::ComponentData {
120 entity_type: (self.entity_type).to_string(),
121 match_type: (self.match_type),
122 match_: (self.match_).map(|s| s.to_string()),
123 unknown_tagged_fields: self.unknown_tagged_fields.clone(),
124 }
125 }
126}
127
128impl<'a> Encode for ComponentData<'a> {
129 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
130 let flex = version >= 1;
131 if version >= 0 { if flex { put_compact_string(buf, self.entity_type) } else { put_string(buf, self.entity_type) } }
132 if version >= 0 { put_i8(buf, self.match_type) }
133 if version >= 0 { if flex { put_compact_nullable_string(buf, self.match_) } else { put_nullable_string(buf, self.match_) } }
134 if flex {
135 let tagged = WriteTaggedFields::new();
136 tagged.write(buf, &self.unknown_tagged_fields);
137 }
138 Ok(())
139 }
140 fn encoded_len(&self, version: i16) -> usize {
141 let flex = version >= 1;
142 let mut n: usize = 0;
143 if version >= 0 { n += if flex { compact_string_len(self.entity_type) } else { string_len(self.entity_type) }; }
144 if version >= 0 { n += 1; }
145 if version >= 0 { n += if flex { compact_nullable_string_len(self.match_) } else { nullable_string_len(self.match_) }; }
146 if flex {
147 let known_pairs: Vec<(u32, usize)> = Vec::new();
148 n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
149 }
150 n
151 }
152}
153
154impl<'de> DecodeBorrow<'de> for ComponentData<'de> {
155 fn decode_borrow(buf: &mut &'de [u8], version: i16) -> Result<Self, ProtocolError> {
156 let flex = version >= 1;
157 let mut out = Self::default();
158 if version >= 0 { out.entity_type = if flex { get_compact_string_borrowed(buf)? } else { get_string_borrowed(buf)? }; }
159 if version >= 0 { out.match_type = get_i8(buf)?; }
160 if version >= 0 { out.match_ = if flex { get_compact_nullable_string_borrowed(buf)? } else { get_nullable_string_borrowed(buf)? }; }
161 if flex {
162 out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| {
163 Ok(false)
164 })?;
165 }
166 Ok(out)
167 }
168}