crabka_protocol/opt/rustwide/workdir/generated/
ControllerRegistrationRequest.borrowed.rs1use bytes::BufMut;
4
5use crate::primitives::fixed::{get_bool, get_i16, get_i32, get_u16, put_bool, put_i16, put_i32, put_u16};
6use crate::primitives::string_bytes::{
7 compact_string_len, put_compact_string, put_string, string_len,
8};
9use crate::primitives::string_bytes_borrowed::{
10 get_compact_string_borrowed, get_string_borrowed,
11};
12use crate::tagged_fields::{read_tagged_fields, tagged_fields_len, WriteTaggedFields};
13use crate::{DecodeBorrow, Encode, ProtocolError, UnknownTaggedFields};
14
15pub const API_KEY: i16 = 70;
16pub const MIN_VERSION: i16 = 0;
17pub const MAX_VERSION: i16 = 0;
18pub const FLEXIBLE_MIN: i16 = 0;
19
20#[inline]
21fn is_flexible(version: i16) -> bool { version >= FLEXIBLE_MIN }
22
23#[derive(Debug, Clone, PartialEq, Eq)]
24pub struct ControllerRegistrationRequest<'a> {
25 pub controller_id: i32,
26 pub incarnation_id: crate::primitives::uuid::Uuid,
27 pub zk_migration_ready: bool,
28 pub listeners: Vec<Listener<'a>>,
29 pub features: Vec<Feature<'a>>,
30 pub unknown_tagged_fields: UnknownTaggedFields,
31}
32
33impl<'a> Default for ControllerRegistrationRequest<'a> {
34 fn default() -> Self {
35 Self {
36 controller_id: 0i32,
37 incarnation_id: Default::default(),
38 zk_migration_ready: false,
39 listeners: Vec::new(),
40 features: Vec::new(),
41 unknown_tagged_fields: Default::default(),
42 }
43 }
44}
45
46impl<'a> ControllerRegistrationRequest<'a> {
47 pub fn to_owned(&self) -> crate::owned::controller_registration_request::ControllerRegistrationRequest {
48 crate::owned::controller_registration_request::ControllerRegistrationRequest {
49 controller_id: (self.controller_id),
50 incarnation_id: (self.incarnation_id),
51 zk_migration_ready: (self.zk_migration_ready),
52 listeners: (self.listeners).iter().map(|it| it.to_owned()).collect(),
53 features: (self.features).iter().map(|it| it.to_owned()).collect(),
54 unknown_tagged_fields: self.unknown_tagged_fields.clone(),
55 }
56 }
57}
58
59impl<'a> Encode for ControllerRegistrationRequest<'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 { put_i32(buf, self.controller_id) }
66 if version >= 0 { crate::primitives::uuid::put_uuid(buf, self.incarnation_id) }
67 if version >= 0 { put_bool(buf, self.zk_migration_ready) }
68 if version >= 0 { { crate::primitives::array::put_array_len(buf, (self.listeners).len(), flex); for it in &self.listeners { it.encode(buf, version)?; } } }
69 if version >= 0 { { crate::primitives::array::put_array_len(buf, (self.features).len(), flex); for it in &self.features { it.encode(buf, version)?; } } }
70 if flex {
71 let tagged = WriteTaggedFields::new();
72 tagged.write(buf, &self.unknown_tagged_fields);
73 }
74 Ok(())
75 }
76 fn encoded_len(&self, version: i16) -> usize {
77 let flex = is_flexible(version);
78 let mut n: usize = 0;
79 if version >= 0 { n += 4; }
80 if version >= 0 { n += 16; }
81 if version >= 0 { n += 1; }
82 if version >= 0 { n += { let prefix = crate::primitives::array::array_len_prefix_len((self.listeners).len(), flex); let body: usize = (self.listeners).iter().map(|it| it.encoded_len(version)).sum(); prefix + body }; }
83 if version >= 0 { n += { let prefix = crate::primitives::array::array_len_prefix_len((self.features).len(), flex); let body: usize = (self.features).iter().map(|it| it.encoded_len(version)).sum(); prefix + body }; }
84 if flex {
85 let known_pairs: Vec<(u32, usize)> = Vec::new();
86 n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
87 }
88 n
89 }
90}
91
92impl<'de> DecodeBorrow<'de> for ControllerRegistrationRequest<'de> {
93 fn decode_borrow(buf: &mut &'de [u8], version: i16) -> Result<Self, ProtocolError> {
94 if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
95 return Err(ProtocolError::UnsupportedVersion { api_key: API_KEY, version });
96 }
97 let flex = is_flexible(version);
98 let mut out = Self::default();
99 if version >= 0 { out.controller_id = get_i32(buf)?; }
100 if version >= 0 { out.incarnation_id = crate::primitives::uuid::get_uuid(buf)?; }
101 if version >= 0 { out.zk_migration_ready = get_bool(buf)?; }
102 if version >= 0 { out.listeners = { let n = crate::primitives::array::get_array_len(buf, flex)?; let mut v = Vec::with_capacity(n); for _ in 0..n { v.push(Listener::decode_borrow(buf, version)?); } v }; }
103 if version >= 0 { out.features = { let n = crate::primitives::array::get_array_len(buf, flex)?; let mut v = Vec::with_capacity(n); for _ in 0..n { v.push(Feature::decode_borrow(buf, version)?); } v }; }
104 if flex {
105 out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| {
106 Ok(false)
107 })?;
108 }
109 Ok(out)
110 }
111}
112
113#[derive(Debug, Clone, PartialEq, Eq)]
114pub struct Listener<'a> {
115 pub name: &'a str,
116 pub host: &'a str,
117 pub port: u16,
118 pub security_protocol: i16,
119 pub unknown_tagged_fields: UnknownTaggedFields,
120}
121
122impl<'a> Default for Listener<'a> {
123 fn default() -> Self {
124 Self {
125 name: "",
126 host: "",
127 port: 0u16,
128 security_protocol: 0i16,
129 unknown_tagged_fields: Default::default(),
130 }
131 }
132}
133
134impl<'a> Listener<'a> {
135 pub fn to_owned(&self) -> crate::owned::controller_registration_request::Listener {
136 crate::owned::controller_registration_request::Listener {
137 name: (self.name).to_string(),
138 host: (self.host).to_string(),
139 port: (self.port),
140 security_protocol: (self.security_protocol),
141 unknown_tagged_fields: self.unknown_tagged_fields.clone(),
142 }
143 }
144}
145
146impl<'a> Encode for Listener<'a> {
147 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
148 let flex = version >= 0;
149 if version >= 0 { if flex { put_compact_string(buf, self.name) } else { put_string(buf, self.name) } }
150 if version >= 0 { if flex { put_compact_string(buf, self.host) } else { put_string(buf, self.host) } }
151 if version >= 0 { put_u16(buf, self.port) }
152 if version >= 0 { put_i16(buf, self.security_protocol) }
153 if flex {
154 let tagged = WriteTaggedFields::new();
155 tagged.write(buf, &self.unknown_tagged_fields);
156 }
157 Ok(())
158 }
159 fn encoded_len(&self, version: i16) -> usize {
160 let flex = version >= 0;
161 let mut n: usize = 0;
162 if version >= 0 { n += if flex { compact_string_len(self.name) } else { string_len(self.name) }; }
163 if version >= 0 { n += if flex { compact_string_len(self.host) } else { string_len(self.host) }; }
164 if version >= 0 { n += 2; }
165 if version >= 0 { n += 2; }
166 if flex {
167 let known_pairs: Vec<(u32, usize)> = Vec::new();
168 n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
169 }
170 n
171 }
172}
173
174impl<'de> DecodeBorrow<'de> for Listener<'de> {
175 fn decode_borrow(buf: &mut &'de [u8], version: i16) -> Result<Self, ProtocolError> {
176 let flex = version >= 0;
177 let mut out = Self::default();
178 if version >= 0 { out.name = if flex { get_compact_string_borrowed(buf)? } else { get_string_borrowed(buf)? }; }
179 if version >= 0 { out.host = if flex { get_compact_string_borrowed(buf)? } else { get_string_borrowed(buf)? }; }
180 if version >= 0 { out.port = get_u16(buf)?; }
181 if version >= 0 { out.security_protocol = get_i16(buf)?; }
182 if flex {
183 out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| {
184 Ok(false)
185 })?;
186 }
187 Ok(out)
188 }
189}
190
191#[derive(Debug, Clone, PartialEq, Eq)]
192pub struct Feature<'a> {
193 pub name: &'a str,
194 pub min_supported_version: i16,
195 pub max_supported_version: i16,
196 pub unknown_tagged_fields: UnknownTaggedFields,
197}
198
199impl<'a> Default for Feature<'a> {
200 fn default() -> Self {
201 Self {
202 name: "",
203 min_supported_version: 0i16,
204 max_supported_version: 0i16,
205 unknown_tagged_fields: Default::default(),
206 }
207 }
208}
209
210impl<'a> Feature<'a> {
211 pub fn to_owned(&self) -> crate::owned::controller_registration_request::Feature {
212 crate::owned::controller_registration_request::Feature {
213 name: (self.name).to_string(),
214 min_supported_version: (self.min_supported_version),
215 max_supported_version: (self.max_supported_version),
216 unknown_tagged_fields: self.unknown_tagged_fields.clone(),
217 }
218 }
219}
220
221impl<'a> Encode for Feature<'a> {
222 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
223 let flex = version >= 0;
224 if version >= 0 { if flex { put_compact_string(buf, self.name) } else { put_string(buf, self.name) } }
225 if version >= 0 { put_i16(buf, self.min_supported_version) }
226 if version >= 0 { put_i16(buf, self.max_supported_version) }
227 if flex {
228 let tagged = WriteTaggedFields::new();
229 tagged.write(buf, &self.unknown_tagged_fields);
230 }
231 Ok(())
232 }
233 fn encoded_len(&self, version: i16) -> usize {
234 let flex = version >= 0;
235 let mut n: usize = 0;
236 if version >= 0 { n += if flex { compact_string_len(self.name) } else { string_len(self.name) }; }
237 if version >= 0 { n += 2; }
238 if version >= 0 { n += 2; }
239 if flex {
240 let known_pairs: Vec<(u32, usize)> = Vec::new();
241 n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
242 }
243 n
244 }
245}
246
247impl<'de> DecodeBorrow<'de> for Feature<'de> {
248 fn decode_borrow(buf: &mut &'de [u8], version: i16) -> Result<Self, ProtocolError> {
249 let flex = version >= 0;
250 let mut out = Self::default();
251 if version >= 0 { out.name = if flex { get_compact_string_borrowed(buf)? } else { get_string_borrowed(buf)? }; }
252 if version >= 0 { out.min_supported_version = get_i16(buf)?; }
253 if version >= 0 { out.max_supported_version = get_i16(buf)?; }
254 if flex {
255 out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| {
256 Ok(false)
257 })?;
258 }
259 Ok(out)
260 }
261}