crabka_protocol/opt/rustwide/workdir/generated/
ControllerRegistrationRequest.owned.rs1use bytes::{Buf, 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, get_compact_string_owned, get_string_owned,
8 put_compact_string, put_string, string_len,
9};
10use crate::tagged_fields::{read_tagged_fields, tagged_fields_len, WriteTaggedFields};
11use crate::{Decode, Encode, ProtocolError, UnknownTaggedFields};
12
13pub const API_KEY: i16 = 70;
14pub const MIN_VERSION: i16 = 0;
15pub const MAX_VERSION: i16 = 0;
16pub const FLEXIBLE_MIN: i16 = 0;
17
18#[inline]
19fn is_flexible(version: i16) -> bool { version >= FLEXIBLE_MIN }
20
21#[derive(Debug, Clone, PartialEq, Eq, Default)]
22pub struct ControllerRegistrationRequest {
23 pub controller_id: i32,
24 pub incarnation_id: crate::primitives::uuid::Uuid,
25 pub zk_migration_ready: bool,
26 pub listeners: Vec<Listener>,
27 pub features: Vec<Feature>,
28 pub unknown_tagged_fields: UnknownTaggedFields,
29}
30
31impl Encode for ControllerRegistrationRequest {
32 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
33 if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
34 return Err(ProtocolError::UnsupportedVersion { api_key: API_KEY, version });
35 }
36 let flex = is_flexible(version);
37 if version >= 0 { put_i32(buf, self.controller_id) }
38 if version >= 0 { crate::primitives::uuid::put_uuid(buf, self.incarnation_id) }
39 if version >= 0 { put_bool(buf, self.zk_migration_ready) }
40 if version >= 0 { { crate::primitives::array::put_array_len(buf, (self.listeners).len(), flex); for it in &self.listeners { it.encode(buf, version)?; } } }
41 if version >= 0 { { crate::primitives::array::put_array_len(buf, (self.features).len(), flex); for it in &self.features { it.encode(buf, version)?; } } }
42 if flex {
43 let tagged = WriteTaggedFields::new();
44 tagged.write(buf, &self.unknown_tagged_fields);
45 }
46 Ok(())
47 }
48 fn encoded_len(&self, version: i16) -> usize {
49 let flex = is_flexible(version);
50 let mut n: usize = 0;
51 if version >= 0 { n += 4; }
52 if version >= 0 { n += 16; }
53 if version >= 0 { n += 1; }
54 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 }; }
55 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 }; }
56 if flex {
57 let known_pairs: Vec<(u32, usize)> = Vec::new();
58 n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
59 }
60 n
61 }
62}
63
64impl<'de> Decode<'de> for ControllerRegistrationRequest {
65 fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
66 if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
67 return Err(ProtocolError::UnsupportedVersion { api_key: API_KEY, version });
68 }
69 let flex = is_flexible(version);
70 let mut out = Self::default();
71 if version >= 0 { out.controller_id = get_i32(buf)?; }
72 if version >= 0 { out.incarnation_id = crate::primitives::uuid::get_uuid(buf)?; }
73 if version >= 0 { out.zk_migration_ready = get_bool(buf)?; }
74 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(buf, version)?); } v }; }
75 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(buf, version)?); } v }; }
76 if flex {
77 out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| {
78 Ok(false)
79 })?;
80 }
81 Ok(out)
82 }
83}
84
85#[derive(Debug, Clone, PartialEq, Eq, Default)]
86pub struct Listener {
87 pub name: String,
88 pub host: String,
89 pub port: u16,
90 pub security_protocol: i16,
91 pub unknown_tagged_fields: UnknownTaggedFields,
92}
93
94impl Encode for Listener {
95 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
96 let flex = version >= 0;
97 if version >= 0 { if flex { put_compact_string(buf, &self.name) } else { put_string(buf, &self.name) } }
98 if version >= 0 { if flex { put_compact_string(buf, &self.host) } else { put_string(buf, &self.host) } }
99 if version >= 0 { put_u16(buf, self.port) }
100 if version >= 0 { put_i16(buf, self.security_protocol) }
101 if flex {
102 let tagged = WriteTaggedFields::new();
103 tagged.write(buf, &self.unknown_tagged_fields);
104 }
105 Ok(())
106 }
107 fn encoded_len(&self, version: i16) -> usize {
108 let flex = version >= 0;
109 let mut n: usize = 0;
110 if version >= 0 { n += if flex { compact_string_len(&self.name) } else { string_len(&self.name) }; }
111 if version >= 0 { n += if flex { compact_string_len(&self.host) } else { string_len(&self.host) }; }
112 if version >= 0 { n += 2; }
113 if version >= 0 { n += 2; }
114 if flex {
115 let known_pairs: Vec<(u32, usize)> = Vec::new();
116 n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
117 }
118 n
119 }
120}
121
122impl<'de> Decode<'de> for Listener {
123 fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
124 let flex = version >= 0;
125 let mut out = Self::default();
126 if version >= 0 { out.name = if flex { get_compact_string_owned(buf)? } else { get_string_owned(buf)? }; }
127 if version >= 0 { out.host = if flex { get_compact_string_owned(buf)? } else { get_string_owned(buf)? }; }
128 if version >= 0 { out.port = get_u16(buf)?; }
129 if version >= 0 { out.security_protocol = get_i16(buf)?; }
130 if flex {
131 out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| {
132 Ok(false)
133 })?;
134 }
135 Ok(out)
136 }
137}
138
139#[derive(Debug, Clone, PartialEq, Eq, Default)]
140pub struct Feature {
141 pub name: String,
142 pub min_supported_version: i16,
143 pub max_supported_version: i16,
144 pub unknown_tagged_fields: UnknownTaggedFields,
145}
146
147impl Encode for Feature {
148 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
149 let flex = version >= 0;
150 if version >= 0 { if flex { put_compact_string(buf, &self.name) } else { put_string(buf, &self.name) } }
151 if version >= 0 { put_i16(buf, self.min_supported_version) }
152 if version >= 0 { put_i16(buf, self.max_supported_version) }
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 += 2; }
164 if version >= 0 { n += 2; }
165 if flex {
166 let known_pairs: Vec<(u32, usize)> = Vec::new();
167 n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
168 }
169 n
170 }
171}
172
173impl<'de> Decode<'de> for Feature {
174 fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
175 let flex = version >= 0;
176 let mut out = Self::default();
177 if version >= 0 { out.name = if flex { get_compact_string_owned(buf)? } else { get_string_owned(buf)? }; }
178 if version >= 0 { out.min_supported_version = get_i16(buf)?; }
179 if version >= 0 { out.max_supported_version = get_i16(buf)?; }
180 if flex {
181 out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| {
182 Ok(false)
183 })?;
184 }
185 Ok(out)
186 }
187}
188
189#[must_use]
192#[allow(unused_comparisons)]
193pub fn default_json(version: i16) -> ::serde_json::Value {
194 let mut obj = ::serde_json::Map::new();
195 obj.insert("controllerId".to_string(), ::serde_json::json!(0));
196 obj.insert("incarnationId".to_string(), ::serde_json::Value::String("AAAAAAAAAAAAAAAAAAAAAA".to_string()));
197 obj.insert("zkMigrationReady".to_string(), ::serde_json::Value::Bool(false));
198 obj.insert("listeners".to_string(), ::serde_json::Value::Array(vec![]));
199 obj.insert("features".to_string(), ::serde_json::Value::Array(vec![]));
200 ::serde_json::Value::Object(obj)
201}
202
203impl crate::ProtocolRequest for ControllerRegistrationRequest {
204 const API_KEY: i16 = API_KEY;
205 const MIN_VERSION: i16 = MIN_VERSION;
206 const MAX_VERSION: i16 = MAX_VERSION;
207 const FLEXIBLE_MIN: i16 = FLEXIBLE_MIN;
208 type Response = super::controller_registration_response::ControllerRegistrationResponse;
209}