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