krabka_protocol/opt/rustwide/workdir/generated/
ApiVersionsRequest.owned.rs1use bytes::{Buf, BufMut};
4
5use crate::{
6 Decode, Encode, ProtocolError, UnknownTaggedFields,
7 primitives::{
8 fixed::{get_i32, put_i32},
9 string_bytes::{
10 compact_nullable_string_len, compact_string_len, get_compact_nullable_string_owned,
11 get_compact_string_owned, get_nullable_string_owned, get_string_owned,
12 nullable_string_len, put_compact_nullable_string, put_compact_string,
13 put_nullable_string, put_string, string_len,
14 },
15 },
16 tagged_fields::{WriteTaggedFields, read_tagged_fields, tagged_fields_len},
17};
18pub const API_KEY: i16 = 18;
19pub const MIN_VERSION: i16 = 0;
20pub const MAX_VERSION: i16 = 5;
21pub const LATEST_STABLE_VERSION: i16 = 5;
22pub const FLEXIBLE_MIN: i16 = 3;
23#[inline]
24#[must_use]
25pub fn is_flexible(version: i16) -> bool {
26 version >= FLEXIBLE_MIN
27}
28#[derive(Debug, Clone, PartialEq, Eq)]
29pub struct ApiVersionsRequest {
30 pub client_software_name: String,
31 pub client_software_version: String,
32 pub cluster_id: Option<String>,
33 pub node_id: i32,
34 pub unknown_tagged_fields: UnknownTaggedFields,
35}
36impl Default for ApiVersionsRequest {
37 fn default() -> Self {
38 Self {
39 client_software_name: String::new(),
40 client_software_version: String::new(),
41 cluster_id: None,
42 node_id: -1i32,
43 unknown_tagged_fields: UnknownTaggedFields::default(),
44 }
45 }
46}
47impl Encode for ApiVersionsRequest {
48 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
49 if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
50 return Err(ProtocolError::UnsupportedVersion {
51 api_key: API_KEY,
52 version,
53 });
54 }
55 let flex = is_flexible(version);
56 if version >= 3 {
57 if flex {
58 let () = put_compact_string(buf, &self.client_software_name);
59 } else {
60 let () = put_string(buf, &self.client_software_name);
61 }
62 }
63 if version >= 3 {
64 if flex {
65 let () = put_compact_string(buf, &self.client_software_version);
66 } else {
67 let () = put_string(buf, &self.client_software_version);
68 }
69 }
70 if version >= 5 {
71 if flex {
72 let () = put_compact_nullable_string(buf, self.cluster_id.as_deref());
73 } else {
74 let () = put_nullable_string(buf, self.cluster_id.as_deref());
75 }
76 }
77 if version >= 5 {
78 put_i32(buf, self.node_id);
79 }
80 if flex {
81 let tagged = WriteTaggedFields::new();
82 tagged.write(buf, &self.unknown_tagged_fields);
83 }
84 Ok(())
85 }
86 fn encoded_len(&self, version: i16) -> usize {
87 let flex = is_flexible(version);
88 let mut n: usize = 0;
89 if version >= 3 {
90 n += if flex {
91 compact_string_len(&self.client_software_name)
92 } else {
93 string_len(&self.client_software_name)
94 };
95 }
96 if version >= 3 {
97 n += if flex {
98 compact_string_len(&self.client_software_version)
99 } else {
100 string_len(&self.client_software_version)
101 };
102 }
103 if version >= 5 {
104 n += if flex {
105 compact_nullable_string_len(self.cluster_id.as_deref())
106 } else {
107 nullable_string_len(self.cluster_id.as_deref())
108 };
109 }
110 if version >= 5 {
111 n += 4;
112 }
113 if flex {
114 let known_pairs: Vec<(u32, usize)> = Vec::new();
115 n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
116 }
117 n
118 }
119}
120impl Decode<'_> for ApiVersionsRequest {
121 fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
122 if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
123 return Err(ProtocolError::UnsupportedVersion {
124 api_key: API_KEY,
125 version,
126 });
127 }
128 let flex = is_flexible(version);
129 let mut out = Self::default();
130 if version >= 3 {
131 out.client_software_name = if flex {
132 get_compact_string_owned(buf)?
133 } else {
134 get_string_owned(buf)?
135 };
136 }
137 if version >= 3 {
138 out.client_software_version = if flex {
139 get_compact_string_owned(buf)?
140 } else {
141 get_string_owned(buf)?
142 };
143 }
144 if version >= 5 {
145 out.cluster_id = if flex {
146 get_compact_nullable_string_owned(buf)?
147 } else {
148 get_nullable_string_owned(buf)?
149 };
150 }
151 if version >= 5 {
152 out.node_id = get_i32(buf)?;
153 }
154 if flex {
155 out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
156 }
157 Ok(out)
158 }
159}
160#[cfg(test)]
161impl ApiVersionsRequest {
162 #[must_use]
163 pub fn populated(version: i16) -> Self {
164 let mut m = Self::default();
165 if version >= 3 {
166 m.client_software_name = "x".to_string();
167 }
168 if version >= 3 {
169 m.client_software_version = "x".to_string();
170 }
171 if version >= 5 {
172 m.cluster_id = Some("x".to_string());
173 }
174 if version >= 5 {
175 m.node_id = 1i32;
176 }
177 m
178 }
179}
180#[must_use]
183#[allow(unused_comparisons)]
184pub fn default_json(version: i16) -> ::serde_json::Value {
185 let mut obj = ::serde_json::Map::new();
186 if version >= 3 {
187 obj.insert(
188 "clientSoftwareName".to_string(),
189 ::serde_json::Value::String(String::new()),
190 );
191 }
192 if version >= 3 {
193 obj.insert(
194 "clientSoftwareVersion".to_string(),
195 ::serde_json::Value::String(String::new()),
196 );
197 }
198 if version >= 5 {
199 obj.insert("clusterId".to_string(), ::serde_json::Value::Null);
200 }
201 if version >= 5 {
202 obj.insert("nodeId".to_string(), ::serde_json::json!(-1));
203 }
204 ::serde_json::Value::Object(obj)
205}
206impl crate::ProtocolRequest for ApiVersionsRequest {
207 const API_KEY: i16 = API_KEY;
208 const MIN_VERSION: i16 = MIN_VERSION;
209 const MAX_VERSION: i16 = MAX_VERSION;
210 const LATEST_STABLE_VERSION: i16 = LATEST_STABLE_VERSION;
211 const FLEXIBLE_MIN: i16 = FLEXIBLE_MIN;
212 type Response = super::api_versions_response::ApiVersionsResponse;
213}