crabka_protocol/opt/rustwide/workdir/generated/
ControllerRegistrationResponse.borrowed.rs1use crate::primitives::fixed::{get_i16, get_i32, put_i16, put_i32};
3use crate::primitives::string_bytes::{
4 compact_nullable_string_len, nullable_string_len, put_compact_nullable_string,
5 put_nullable_string,
6};
7use crate::primitives::string_bytes_borrowed::{
8 get_compact_nullable_string_borrowed, get_nullable_string_borrowed,
9};
10use crate::tagged_fields::{WriteTaggedFields, read_tagged_fields, tagged_fields_len};
11use crate::{DecodeBorrow, Encode, ProtocolError, UnknownTaggedFields};
12use bytes::BufMut;
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#[inline]
18fn is_flexible(version: i16) -> bool {
19 version >= FLEXIBLE_MIN
20}
21#[derive(Debug, Clone, PartialEq, Eq, Default)]
22pub struct ControllerRegistrationResponse<'a> {
23 pub throttle_time_ms: i32,
24 pub error_code: i16,
25 pub error_message: Option<&'a str>,
26 pub unknown_tagged_fields: UnknownTaggedFields,
27}
28impl ControllerRegistrationResponse<'_> {
29 pub fn to_owned(
30 &self,
31 ) -> crate::owned::controller_registration_response::ControllerRegistrationResponse {
32 crate::owned::controller_registration_response::ControllerRegistrationResponse {
33 throttle_time_ms: (self.throttle_time_ms),
34 error_code: (self.error_code),
35 error_message: (self.error_message).map(std::string::ToString::to_string),
36 unknown_tagged_fields: self.unknown_tagged_fields.clone(),
37 }
38 }
39}
40impl Encode for ControllerRegistrationResponse<'_> {
41 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
42 if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
43 return Err(ProtocolError::UnsupportedVersion {
44 api_key: API_KEY,
45 version,
46 });
47 }
48 let flex = is_flexible(version);
49 if version >= 0 {
50 put_i32(buf, self.throttle_time_ms);
51 }
52 if version >= 0 {
53 put_i16(buf, self.error_code);
54 }
55 if version >= 0 {
56 if flex {
57 put_compact_nullable_string(buf, self.error_message);
58 } else {
59 put_nullable_string(buf, self.error_message);
60 }
61 }
62 if flex {
63 let tagged = WriteTaggedFields::new();
64 tagged.write(buf, &self.unknown_tagged_fields);
65 }
66 Ok(())
67 }
68 fn encoded_len(&self, version: i16) -> usize {
69 let flex = is_flexible(version);
70 let mut n: usize = 0;
71 if version >= 0 {
72 n += 4;
73 }
74 if version >= 0 {
75 n += 2;
76 }
77 if version >= 0 {
78 n += if flex {
79 compact_nullable_string_len(self.error_message)
80 } else {
81 nullable_string_len(self.error_message)
82 };
83 }
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}
91impl<'de> DecodeBorrow<'de> for ControllerRegistrationResponse<'de> {
92 fn decode_borrow(buf: &mut &'de [u8], version: i16) -> Result<Self, ProtocolError> {
93 if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
94 return Err(ProtocolError::UnsupportedVersion {
95 api_key: API_KEY,
96 version,
97 });
98 }
99 let flex = is_flexible(version);
100 let mut out = Self::default();
101 if version >= 0 {
102 out.throttle_time_ms = get_i32(buf)?;
103 }
104 if version >= 0 {
105 out.error_code = get_i16(buf)?;
106 }
107 if version >= 0 {
108 out.error_message = if flex {
109 get_compact_nullable_string_borrowed(buf)?
110 } else {
111 get_nullable_string_borrowed(buf)?
112 };
113 }
114 if flex {
115 out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
116 }
117 Ok(out)
118 }
119}
120#[cfg(test)]
121impl ControllerRegistrationResponse<'_> {
122 #[must_use]
123 pub fn populated(version: i16) -> Self {
124 let mut m = Self::default();
125 if version >= 0 {
126 m.throttle_time_ms = 1i32;
127 }
128 if version >= 0 {
129 m.error_code = 1i16;
130 }
131 if version >= 0 {
132 m.error_message = Some("x");
133 }
134 m
135 }
136}