crabka_protocol/opt/rustwide/workdir/generated/
MetadataRequest.owned.rs1use bytes::{Buf, BufMut};
4
5use crate::primitives::fixed::{get_bool, put_bool};
6use crate::primitives::string_bytes::{
7 compact_nullable_string_len, compact_string_len, get_compact_nullable_string_owned,
8 get_compact_string_owned, get_nullable_string_owned, get_string_owned, nullable_string_len,
9 put_compact_nullable_string, put_compact_string, put_nullable_string, put_string,
10 string_len,
11};
12use crate::tagged_fields::{read_tagged_fields, tagged_fields_len, WriteTaggedFields};
13use crate::{Decode, Encode, ProtocolError, UnknownTaggedFields};
14
15pub const API_KEY: i16 = 3;
16pub const MIN_VERSION: i16 = 0;
17pub const MAX_VERSION: i16 = 13;
18pub const FLEXIBLE_MIN: i16 = 9;
19
20#[inline]
21fn is_flexible(version: i16) -> bool { version >= FLEXIBLE_MIN }
22
23#[derive(Debug, Clone, PartialEq, Eq)]
24pub struct MetadataRequest {
25 pub topics: Option<Vec<MetadataRequestTopic>>,
26 pub allow_auto_topic_creation: bool,
27 pub include_cluster_authorized_operations: bool,
28 pub include_topic_authorized_operations: bool,
29 pub unknown_tagged_fields: UnknownTaggedFields,
30}
31
32impl Default for MetadataRequest {
33 fn default() -> Self {
34 Self {
35 topics: None,
36 allow_auto_topic_creation: true,
37 include_cluster_authorized_operations: false,
38 include_topic_authorized_operations: false,
39 unknown_tagged_fields: Default::default(),
40 }
41 }
42}
43
44impl Encode for MetadataRequest {
45 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
46 if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
47 return Err(ProtocolError::UnsupportedVersion { api_key: API_KEY, version });
48 }
49 let flex = is_flexible(version);
50 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)?; } } } }
51 if version >= 4 { put_bool(buf, self.allow_auto_topic_creation) }
52 if version >= 8 && version <= 10 { put_bool(buf, self.include_cluster_authorized_operations) }
53 if version >= 8 { put_bool(buf, self.include_topic_authorized_operations) }
54 if flex {
55 let tagged = WriteTaggedFields::new();
56 tagged.write(buf, &self.unknown_tagged_fields);
57 }
58 Ok(())
59 }
60 fn encoded_len(&self, version: i16) -> usize {
61 let flex = is_flexible(version);
62 let mut n: usize = 0;
63 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 } }; }
64 if version >= 4 { n += 1; }
65 if version >= 8 && version <= 10 { n += 1; }
66 if version >= 8 { n += 1; }
67 if flex {
68 let known_pairs: Vec<(u32, usize)> = Vec::new();
69 n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
70 }
71 n
72 }
73}
74
75impl<'de> Decode<'de> for MetadataRequest {
76 fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
77 if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
78 return Err(ProtocolError::UnsupportedVersion { api_key: API_KEY, version });
79 }
80 let flex = is_flexible(version);
81 let mut out = Self::default();
82 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(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(buf, version)?); } v }) }; }
83 if version >= 4 { out.allow_auto_topic_creation = get_bool(buf)?; }
84 if version >= 8 && version <= 10 { out.include_cluster_authorized_operations = get_bool(buf)?; }
85 if version >= 8 { out.include_topic_authorized_operations = get_bool(buf)?; }
86 if flex {
87 out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| {
88 Ok(false)
89 })?;
90 }
91 Ok(out)
92 }
93}
94
95#[derive(Debug, Clone, PartialEq, Eq, Default)]
96pub struct MetadataRequestTopic {
97 pub topic_id: crate::primitives::uuid::Uuid,
98 pub name: Option<String>,
99 pub unknown_tagged_fields: UnknownTaggedFields,
100}
101
102impl Encode for MetadataRequestTopic {
103 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
104 let flex = version >= 9;
105 if version >= 10 { crate::primitives::uuid::put_uuid(buf, self.topic_id) }
106 if version >= 0 { if version >= 10 { if flex { put_compact_nullable_string(buf, self.name.as_deref()) } else { put_nullable_string(buf, self.name.as_deref()) } } else { if flex { put_compact_string(buf, (self.name).as_deref().unwrap_or("")) } else { put_string(buf, (self.name).as_deref().unwrap_or("")) } } }
107 if flex {
108 let tagged = WriteTaggedFields::new();
109 tagged.write(buf, &self.unknown_tagged_fields);
110 }
111 Ok(())
112 }
113 fn encoded_len(&self, version: i16) -> usize {
114 let flex = version >= 9;
115 let mut n: usize = 0;
116 if version >= 10 { n += 16; }
117 if version >= 0 { n += if version >= 10 { if flex { compact_nullable_string_len(self.name.as_deref()) } else { nullable_string_len(self.name.as_deref()) } } else { if flex { compact_string_len((self.name).as_deref().unwrap_or("")) } else { string_len((self.name).as_deref().unwrap_or("")) } }; }
118 if flex {
119 let known_pairs: Vec<(u32, usize)> = Vec::new();
120 n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
121 }
122 n
123 }
124}
125
126impl<'de> Decode<'de> for MetadataRequestTopic {
127 fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
128 let flex = version >= 9;
129 let mut out = Self::default();
130 if version >= 10 { out.topic_id = crate::primitives::uuid::get_uuid(buf)?; }
131 if version >= 0 { out.name = if version >= 10 { if flex { get_compact_nullable_string_owned(buf)? } else { get_nullable_string_owned(buf)? } } else { Some(if flex { get_compact_string_owned(buf)? } else { get_string_owned(buf)? }) }; }
132 if flex {
133 out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| {
134 Ok(false)
135 })?;
136 }
137 Ok(out)
138 }
139}
140
141#[must_use]
144#[allow(unused_comparisons)]
145pub fn default_json(version: i16) -> ::serde_json::Value {
146 let mut obj = ::serde_json::Map::new();
147 obj.insert("topics".to_string(), if version >= 1 { ::serde_json::Value::Null } else { ::serde_json::Value::Array(vec![]) });
148 if version >= 4 {
149 obj.insert("allowAutoTopicCreation".to_string(), ::serde_json::Value::Bool(true));
150 }
151 if version >= 8 && version <= 10 {
152 obj.insert("includeClusterAuthorizedOperations".to_string(), ::serde_json::Value::Bool(false));
153 }
154 if version >= 8 {
155 obj.insert("includeTopicAuthorizedOperations".to_string(), ::serde_json::Value::Bool(false));
156 }
157 ::serde_json::Value::Object(obj)
158}
159
160impl crate::ProtocolRequest for MetadataRequest {
161 const API_KEY: i16 = API_KEY;
162 const MIN_VERSION: i16 = MIN_VERSION;
163 const MAX_VERSION: i16 = MAX_VERSION;
164 const FLEXIBLE_MIN: i16 = FLEXIBLE_MIN;
165 type Response = super::metadata_response::MetadataResponse;
166}