crabka_protocol/opt/rustwide/workdir/generated/
ApiVersionsRequest.owned.rs1use crate::primitives::string_bytes::{
4 compact_string_len, get_compact_string_owned, get_string_owned, put_compact_string, put_string,
5 string_len,
6};
7use crate::tagged_fields::{WriteTaggedFields, read_tagged_fields, tagged_fields_len};
8use crate::{Decode, Encode, ProtocolError, UnknownTaggedFields};
9use bytes::{Buf, BufMut};
10pub const API_KEY: i16 = 18;
11pub const MIN_VERSION: i16 = 0;
12pub const MAX_VERSION: i16 = 4;
13pub const FLEXIBLE_MIN: i16 = 3;
14#[inline]
15fn is_flexible(version: i16) -> bool {
16 version >= FLEXIBLE_MIN
17}
18#[derive(Debug, Clone, PartialEq, Eq, Default)]
19pub struct ApiVersionsRequest {
20 pub client_software_name: String,
21 pub client_software_version: String,
22 pub unknown_tagged_fields: UnknownTaggedFields,
23}
24impl Encode for ApiVersionsRequest {
25 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
26 if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
27 return Err(ProtocolError::UnsupportedVersion {
28 api_key: API_KEY,
29 version,
30 });
31 }
32 let flex = is_flexible(version);
33 if version >= 3 {
34 if flex {
35 put_compact_string(buf, &self.client_software_name);
36 } else {
37 put_string(buf, &self.client_software_name);
38 }
39 }
40 if version >= 3 {
41 if flex {
42 put_compact_string(buf, &self.client_software_version);
43 } else {
44 put_string(buf, &self.client_software_version);
45 }
46 }
47 if flex {
48 let tagged = WriteTaggedFields::new();
49 tagged.write(buf, &self.unknown_tagged_fields);
50 }
51 Ok(())
52 }
53 fn encoded_len(&self, version: i16) -> usize {
54 let flex = is_flexible(version);
55 let mut n: usize = 0;
56 if version >= 3 {
57 n += if flex {
58 compact_string_len(&self.client_software_name)
59 } else {
60 string_len(&self.client_software_name)
61 };
62 }
63 if version >= 3 {
64 n += if flex {
65 compact_string_len(&self.client_software_version)
66 } else {
67 string_len(&self.client_software_version)
68 };
69 }
70 if flex {
71 let known_pairs: Vec<(u32, usize)> = Vec::new();
72 n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
73 }
74 n
75 }
76}
77impl Decode<'_> for ApiVersionsRequest {
78 fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
79 if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
80 return Err(ProtocolError::UnsupportedVersion {
81 api_key: API_KEY,
82 version,
83 });
84 }
85 let flex = is_flexible(version);
86 let mut out = Self::default();
87 if version >= 3 {
88 out.client_software_name = if flex {
89 get_compact_string_owned(buf)?
90 } else {
91 get_string_owned(buf)?
92 };
93 }
94 if version >= 3 {
95 out.client_software_version = if flex {
96 get_compact_string_owned(buf)?
97 } else {
98 get_string_owned(buf)?
99 };
100 }
101 if flex {
102 out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
103 }
104 Ok(out)
105 }
106}
107#[cfg(test)]
108impl ApiVersionsRequest {
109 #[must_use]
110 pub fn populated(version: i16) -> Self {
111 let mut m = Self::default();
112 if version >= 3 {
113 m.client_software_name = "x".to_string();
114 }
115 if version >= 3 {
116 m.client_software_version = "x".to_string();
117 }
118 m
119 }
120}
121#[must_use]
124#[allow(unused_comparisons)]
125pub fn default_json(version: i16) -> ::serde_json::Value {
126 let mut obj = ::serde_json::Map::new();
127 if version >= 3 {
128 obj.insert(
129 "clientSoftwareName".to_string(),
130 ::serde_json::Value::String(String::new()),
131 );
132 }
133 if version >= 3 {
134 obj.insert(
135 "clientSoftwareVersion".to_string(),
136 ::serde_json::Value::String(String::new()),
137 );
138 }
139 ::serde_json::Value::Object(obj)
140}
141impl crate::ProtocolRequest for ApiVersionsRequest {
142 const API_KEY: i16 = API_KEY;
143 const MIN_VERSION: i16 = MIN_VERSION;
144 const MAX_VERSION: i16 = MAX_VERSION;
145 const FLEXIBLE_MIN: i16 = FLEXIBLE_MIN;
146 type Response = super::api_versions_response::ApiVersionsResponse;
147}