krabka_protocol/opt/rustwide/workdir/generated/
StreamsGroupTopologyDescriptionUpdateResponse.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 = 93;
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, Default)]
28pub struct StreamsGroupTopologyDescriptionUpdateResponse<'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 StreamsGroupTopologyDescriptionUpdateResponse<'_> {
35 #[must_use]
39 pub fn to_owned(&self) -> crate::owned::streams_group_topology_description_update_response::StreamsGroupTopologyDescriptionUpdateResponse{
40 crate::owned::streams_group_topology_description_update_response::StreamsGroupTopologyDescriptionUpdateResponse {
41 throttle_time_ms: (self.throttle_time_ms),
42 error_code: (self.error_code),
43 error_message: (self.error_message).map(std::string::ToString::to_string),
44 unknown_tagged_fields: self.unknown_tagged_fields.clone(),
45 }
46 }
47}
48impl Encode for StreamsGroupTopologyDescriptionUpdateResponse<'_> {
49 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
50 if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
51 return Err(ProtocolError::UnsupportedVersion {
52 api_key: API_KEY,
53 version,
54 });
55 }
56 let flex = is_flexible(version);
57 if version >= 0 {
58 put_i32(buf, self.throttle_time_ms);
59 }
60 if version >= 0 {
61 put_i16(buf, self.error_code);
62 }
63 if version >= 0 {
64 if flex {
65 let () = put_compact_nullable_string(buf, self.error_message);
66 } else {
67 let () = put_nullable_string(buf, self.error_message);
68 }
69 }
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 {
80 n += 4;
81 }
82 if version >= 0 {
83 n += 2;
84 }
85 if version >= 0 {
86 n += if flex {
87 compact_nullable_string_len(self.error_message)
88 } else {
89 nullable_string_len(self.error_message)
90 };
91 }
92 if flex {
93 let known_pairs: Vec<(u32, usize)> = Vec::new();
94 n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
95 }
96 n
97 }
98}
99impl<'de> DecodeBorrow<'de> for StreamsGroupTopologyDescriptionUpdateResponse<'de> {
100 fn decode_borrow(buf: &mut &'de [u8], version: i16) -> Result<Self, ProtocolError> {
101 if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
102 return Err(ProtocolError::UnsupportedVersion {
103 api_key: API_KEY,
104 version,
105 });
106 }
107 let flex = is_flexible(version);
108 let mut out = Self::default();
109 if version >= 0 {
110 out.throttle_time_ms = get_i32(buf)?;
111 }
112 if version >= 0 {
113 out.error_code = get_i16(buf)?;
114 }
115 if version >= 0 {
116 out.error_message = if flex {
117 get_compact_nullable_string_borrowed(buf)?
118 } else {
119 get_nullable_string_borrowed(buf)?
120 };
121 }
122 if flex {
123 out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
124 }
125 Ok(out)
126 }
127}
128#[cfg(test)]
129impl StreamsGroupTopologyDescriptionUpdateResponse<'_> {
130 #[must_use]
131 pub fn populated(version: i16) -> Self {
132 let mut m = Self::default();
133 if version >= 0 {
134 m.throttle_time_ms = 1i32;
135 }
136 if version >= 0 {
137 m.error_code = 1i16;
138 }
139 if version >= 0 {
140 m.error_message = Some("x");
141 }
142 m
143 }
144}