crabka_protocol/opt/rustwide/workdir/generated/
MetadataRequest.borrowed.rs1use bytes::BufMut;
4
5use crate::primitives::fixed::{get_bool, put_bool};
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 = 3;
19pub const MIN_VERSION: i16 = 0;
20pub const MAX_VERSION: i16 = 13;
21pub const FLEXIBLE_MIN: i16 = 9;
22
23#[inline]
24fn is_flexible(version: i16) -> bool { version >= FLEXIBLE_MIN }
25
26#[derive(Debug, Clone, PartialEq, Eq)]
27pub struct MetadataRequest<'a> {
28 pub topics: Option<Vec<MetadataRequestTopic<'a>>>,
29 pub allow_auto_topic_creation: bool,
30 pub include_cluster_authorized_operations: bool,
31 pub include_topic_authorized_operations: bool,
32 pub unknown_tagged_fields: UnknownTaggedFields,
33}
34
35impl<'a> Default for MetadataRequest<'a> {
36 fn default() -> Self {
37 Self {
38 topics: None,
39 allow_auto_topic_creation: true,
40 include_cluster_authorized_operations: false,
41 include_topic_authorized_operations: false,
42 unknown_tagged_fields: Default::default(),
43 }
44 }
45}
46
47impl<'a> MetadataRequest<'a> {
48 pub fn to_owned(&self) -> crate::owned::metadata_request::MetadataRequest {
49 crate::owned::metadata_request::MetadataRequest {
50 topics: (self.topics).as_ref().map(|v| v.iter().map(|it| it.to_owned()).collect()),
51 allow_auto_topic_creation: (self.allow_auto_topic_creation),
52 include_cluster_authorized_operations: (self.include_cluster_authorized_operations),
53 include_topic_authorized_operations: (self.include_topic_authorized_operations),
54 unknown_tagged_fields: self.unknown_tagged_fields.clone(),
55 }
56 }
57}
58
59impl<'a> Encode for MetadataRequest<'a> {
60 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
61 if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
62 return Err(ProtocolError::UnsupportedVersion { api_key: API_KEY, version });
63 }
64 let flex = is_flexible(version);
65 if version >= 0 { if version >= 1 { { let len = (self.topics).as_ref().map(Vec::len); crate::primitives::array::put_nullable_array_len(buf, len, flex); if let Some(v) = &self.topics { for it in v { it.encode(buf, version)?; } } } } else { { let v = (self.topics).as_ref().map(Vec::as_slice).unwrap_or(&[]); crate::primitives::array::put_array_len(buf, v.len(), flex); for it in v { it.encode(buf, version)?; } } } }
66 if version >= 4 { put_bool(buf, self.allow_auto_topic_creation) }
67 if version >= 8 && version <= 10 { put_bool(buf, self.include_cluster_authorized_operations) }
68 if version >= 8 { put_bool(buf, self.include_topic_authorized_operations) }
69 if flex {
70 let tagged = WriteTaggedFields::new();
71 tagged.write(buf, &self.unknown_tagged_fields);
72 }
73 Ok(())
74 }
75 fn encoded_len(&self, version: i16) -> usize {
76 let flex = is_flexible(version);
77 let mut n: usize = 0;
78 if version >= 0 { n += if version >= 1 { { let opt: Option<&Vec<_>> = (self.topics).as_ref(); let prefix = crate::primitives::array::nullable_array_len_prefix_len(opt.map(|v| v.len()), flex); let body: usize = opt.map_or(0, |v| v.iter().map(|it| it.encoded_len(version)).sum()); prefix + body } } else { { let v = (self.topics).as_ref().map(Vec::as_slice).unwrap_or(&[]); let prefix = crate::primitives::array::array_len_prefix_len(v.len(), flex); let body: usize = v.iter().map(|it| it.encoded_len(version)).sum(); prefix + body } }; }
79 if version >= 4 { n += 1; }
80 if version >= 8 && version <= 10 { n += 1; }
81 if version >= 8 { n += 1; }
82 if flex {
83 let known_pairs: Vec<(u32, usize)> = Vec::new();
84 n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
85 }
86 n
87 }
88}
89
90impl<'de> DecodeBorrow<'de> for MetadataRequest<'de> {
91 fn decode_borrow(buf: &mut &'de [u8], version: i16) -> Result<Self, ProtocolError> {
92 if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
93 return Err(ProtocolError::UnsupportedVersion { api_key: API_KEY, version });
94 }
95 let flex = is_flexible(version);
96 let mut out = Self::default();
97 if version >= 0 { out.topics = if version >= 1 { { let opt = crate::primitives::array::get_nullable_array_len(buf, flex)?; match opt { None => None, Some(n) => { let mut v = Vec::with_capacity(n); for _ in 0..n { v.push(MetadataRequestTopic::decode_borrow(buf, version)?); } Some(v) } } } } else { Some({ let n = crate::primitives::array::get_array_len(buf, flex)?; let mut v = Vec::with_capacity(n); for _ in 0..n { v.push(MetadataRequestTopic::decode_borrow(buf, version)?); } v }) }; }
98 if version >= 4 { out.allow_auto_topic_creation = get_bool(buf)?; }
99 if version >= 8 && version <= 10 { out.include_cluster_authorized_operations = get_bool(buf)?; }
100 if version >= 8 { out.include_topic_authorized_operations = get_bool(buf)?; }
101 if flex {
102 out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| {
103 Ok(false)
104 })?;
105 }
106 Ok(out)
107 }
108}
109
110#[derive(Debug, Clone, PartialEq, Eq)]
111pub struct MetadataRequestTopic<'a> {
112 pub topic_id: crate::primitives::uuid::Uuid,
113 pub name: Option<&'a str>,
114 pub unknown_tagged_fields: UnknownTaggedFields,
115}
116
117impl<'a> Default for MetadataRequestTopic<'a> {
118 fn default() -> Self {
119 Self {
120 topic_id: Default::default(),
121 name: None,
122 unknown_tagged_fields: Default::default(),
123 }
124 }
125}
126
127impl<'a> MetadataRequestTopic<'a> {
128 pub fn to_owned(&self) -> crate::owned::metadata_request::MetadataRequestTopic {
129 crate::owned::metadata_request::MetadataRequestTopic {
130 topic_id: (self.topic_id),
131 name: (self.name).map(|s| s.to_string()),
132 unknown_tagged_fields: self.unknown_tagged_fields.clone(),
133 }
134 }
135}
136
137impl<'a> Encode for MetadataRequestTopic<'a> {
138 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
139 let flex = version >= 9;
140 if version >= 10 { crate::primitives::uuid::put_uuid(buf, self.topic_id) }
141 if version >= 0 { if version >= 10 { if flex { put_compact_nullable_string(buf, self.name) } else { put_nullable_string(buf, self.name) } } else { if flex { put_compact_string(buf, (self.name).unwrap_or("")) } else { put_string(buf, (self.name).unwrap_or("")) } } }
142 if flex {
143 let tagged = WriteTaggedFields::new();
144 tagged.write(buf, &self.unknown_tagged_fields);
145 }
146 Ok(())
147 }
148 fn encoded_len(&self, version: i16) -> usize {
149 let flex = version >= 9;
150 let mut n: usize = 0;
151 if version >= 10 { n += 16; }
152 if version >= 0 { n += if version >= 10 { if flex { compact_nullable_string_len(self.name) } else { nullable_string_len(self.name) } } else { if flex { compact_string_len((self.name).unwrap_or("")) } else { string_len((self.name).unwrap_or("")) } }; }
153 if flex {
154 let known_pairs: Vec<(u32, usize)> = Vec::new();
155 n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
156 }
157 n
158 }
159}
160
161impl<'de> DecodeBorrow<'de> for MetadataRequestTopic<'de> {
162 fn decode_borrow(buf: &mut &'de [u8], version: i16) -> Result<Self, ProtocolError> {
163 let flex = version >= 9;
164 let mut out = Self::default();
165 if version >= 10 { out.topic_id = crate::primitives::uuid::get_uuid(buf)?; }
166 if version >= 0 { out.name = if version >= 10 { if flex { get_compact_nullable_string_borrowed(buf)? } else { get_nullable_string_borrowed(buf)? } } else { Some(if flex { get_compact_string_borrowed(buf)? } else { get_string_borrowed(buf)? }) }; }
167 if flex {
168 out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| {
169 Ok(false)
170 })?;
171 }
172 Ok(out)
173 }
174}