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