krabka_protocol/opt/rustwide/workdir/generated/
UnregisterControllerResponse.borrowed.rs1use bytes::BufMut;
3
4use crate::{
5 DecodeBorrow, Encode, ProtocolError, UnknownTaggedFields,
6 primitives::{
7 fixed::{get_i16, get_i32, put_i16, put_i32},
8 string_bytes::{
9 compact_nullable_string_len, nullable_string_len, put_compact_nullable_string,
10 put_nullable_string,
11 },
12 string_bytes_borrowed::{
13 get_compact_nullable_string_borrowed, get_nullable_string_borrowed,
14 },
15 },
16 tagged_fields::{WriteTaggedFields, read_tagged_fields, tagged_fields_len},
17};
18pub const API_KEY: i16 = 94;
19pub const MIN_VERSION: i16 = 0;
20pub const MAX_VERSION: i16 = 0;
21pub const FLEXIBLE_MIN: i16 = 0;
22#[inline]
23#[must_use]
24pub fn is_flexible(version: i16) -> bool {
25 version >= FLEXIBLE_MIN
26}
27#[derive(Debug, Clone, PartialEq, Eq)]
28pub struct UnregisterControllerResponse<'a> {
29 pub throttle_time_ms: i32,
30 pub error_code: i16,
31 pub error_message: Option<&'a str>,
32 pub unknown_tagged_fields: UnknownTaggedFields,
33}
34impl Default for UnregisterControllerResponse<'_> {
35 fn default() -> Self {
36 Self {
37 throttle_time_ms: 0i32,
38 error_code: 0i16,
39 error_message: Some(""),
40 unknown_tagged_fields: UnknownTaggedFields::default(),
41 }
42 }
43}
44impl UnregisterControllerResponse<'_> {
45 #[must_use]
49 pub fn to_owned(
50 &self,
51 ) -> crate::owned::unregister_controller_response::UnregisterControllerResponse {
52 crate::owned::unregister_controller_response::UnregisterControllerResponse {
53 throttle_time_ms: (self.throttle_time_ms),
54 error_code: (self.error_code),
55 error_message: (self.error_message).map(std::string::ToString::to_string),
56 unknown_tagged_fields: self.unknown_tagged_fields.clone(),
57 }
58 }
59}
60impl Encode for UnregisterControllerResponse<'_> {
61 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
62 if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
63 return Err(ProtocolError::UnsupportedVersion {
64 api_key: API_KEY,
65 version,
66 });
67 }
68 let flex = is_flexible(version);
69 if version >= 0 {
70 put_i32(buf, self.throttle_time_ms);
71 }
72 if version >= 0 {
73 put_i16(buf, self.error_code);
74 }
75 if version >= 0 {
76 if flex {
77 let () = put_compact_nullable_string(buf, self.error_message);
78 } else {
79 let () = put_nullable_string(buf, self.error_message);
80 }
81 }
82 if flex {
83 let tagged = WriteTaggedFields::new();
84 tagged.write(buf, &self.unknown_tagged_fields);
85 }
86 Ok(())
87 }
88 fn encoded_len(&self, version: i16) -> usize {
89 let flex = is_flexible(version);
90 let mut n: usize = 0;
91 if version >= 0 {
92 n += 4;
93 }
94 if version >= 0 {
95 n += 2;
96 }
97 if version >= 0 {
98 n += if flex {
99 compact_nullable_string_len(self.error_message)
100 } else {
101 nullable_string_len(self.error_message)
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<'de> DecodeBorrow<'de> for UnregisterControllerResponse<'de> {
112 fn decode_borrow(buf: &mut &'de [u8], 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 >= 0 {
122 out.throttle_time_ms = get_i32(buf)?;
123 }
124 if version >= 0 {
125 out.error_code = get_i16(buf)?;
126 }
127 if version >= 0 {
128 out.error_message = if flex {
129 get_compact_nullable_string_borrowed(buf)?
130 } else {
131 get_nullable_string_borrowed(buf)?
132 };
133 }
134 if flex {
135 out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
136 }
137 Ok(out)
138 }
139}
140#[cfg(test)]
141impl UnregisterControllerResponse<'_> {
142 #[must_use]
143 pub fn populated(version: i16) -> Self {
144 let mut m = Self::default();
145 if version >= 0 {
146 m.throttle_time_ms = 1i32;
147 }
148 if version >= 0 {
149 m.error_code = 1i16;
150 }
151 if version >= 0 {
152 m.error_message = Some("x");
153 }
154 m
155 }
156}