kacrab_protocol/generated/
sync_group_response.rs1#![allow(
3 missing_docs,
4 clippy::all,
5 clippy::pedantic,
6 clippy::nursery,
7 clippy::arithmetic_side_effects,
8 reason = "Generated protocol modules mirror Kafka's schema shape and intentionally trade \
9 hand-written lint style for reproducible wire-code output."
10)]
11use bytes::{Bytes, BytesMut};
12
13use crate::*;
14
15#[derive(Debug, Clone, PartialEq)]
16pub struct SyncGroupResponseData {
17 pub throttle_time_ms: i32,
20 pub error_code: i16,
22 pub protocol_type: Option<KafkaString>,
24 pub protocol_name: Option<KafkaString>,
26 pub assignment: Bytes,
28 pub _unknown_tagged_fields: Vec<RawTaggedField>,
29}
30impl Default for SyncGroupResponseData {
31 fn default() -> Self {
32 Self {
33 throttle_time_ms: 0_i32,
34 error_code: 0_i16,
35 protocol_type: None,
36 protocol_name: None,
37 assignment: Bytes::new(),
38 _unknown_tagged_fields: Vec::new(),
39 }
40 }
41}
42impl SyncGroupResponseData {
43 pub fn with_throttle_time_ms(mut self, value: i32) -> Self {
44 self.throttle_time_ms = value;
45 self
46 }
47 pub fn with_error_code(mut self, value: i16) -> Self {
48 self.error_code = value;
49 self
50 }
51 pub fn with_protocol_type(mut self, value: Option<KafkaString>) -> Self {
52 self.protocol_type = value;
53 self
54 }
55 pub fn with_protocol_name(mut self, value: Option<KafkaString>) -> Self {
56 self.protocol_name = value;
57 self
58 }
59 pub fn with_assignment(mut self, value: Bytes) -> Self {
60 self.assignment = value;
61 self
62 }
63 pub fn read(buf: &mut Bytes, version: i16) -> Result<Self> {
64 if version < 0 || version > 5 {
65 return Err(UnsupportedVersion::new(14, version).into());
66 }
67 let mut throttle_time_ms = 0_i32;
68 let error_code;
69 let mut protocol_type = None;
70 let mut protocol_name = None;
71 let assignment;
72 let mut _unknown_tagged_fields: Vec<RawTaggedField> = Vec::new();
73 if version >= 1 {
74 throttle_time_ms = read_i32(buf)?;
75 }
76 error_code = read_i16(buf)?;
77 if version >= 5 {
78 protocol_type = read_compact_nullable_string(buf)?;
79 }
80 if version >= 5 {
81 protocol_name = read_compact_nullable_string(buf)?;
82 }
83 if version >= 4 {
84 assignment = read_compact_bytes(buf)?;
85 } else {
86 assignment = read_bytes(buf)?;
87 }
88 if version >= 4 {
89 let tagged_fields = read_tagged_fields(buf)?;
90 for field in &tagged_fields {
91 match field.tag {
92 _ => {
93 _unknown_tagged_fields.push(field.clone());
94 },
95 }
96 }
97 }
98 Ok(Self {
99 throttle_time_ms,
100 error_code,
101 protocol_type,
102 protocol_name,
103 assignment,
104 _unknown_tagged_fields,
105 })
106 }
107 pub fn write(&self, buf: &mut BytesMut, version: i16) -> Result<()> {
108 if version < 0 || version > 5 {
109 return Err(UnsupportedVersion::new(14, version).into());
110 }
111 if version >= 1 {
112 write_i32(buf, self.throttle_time_ms);
113 } else if self.throttle_time_ms != 0_i32 {
114 return Err(UnsupportedFieldVersion::new(14, "throttle_time_ms", version).into());
115 }
116 write_i16(buf, self.error_code);
117 if version >= 5 {
118 write_compact_nullable_string(buf, self.protocol_type.as_ref())?;
119 } else if self.protocol_type != None {
120 return Err(UnsupportedFieldVersion::new(14, "protocol_type", version).into());
121 }
122 if version >= 5 {
123 write_compact_nullable_string(buf, self.protocol_name.as_ref())?;
124 } else if self.protocol_name != None {
125 return Err(UnsupportedFieldVersion::new(14, "protocol_name", version).into());
126 }
127 if version >= 4 {
128 write_compact_bytes(buf, &self.assignment)?;
129 } else {
130 write_bytes(buf, &self.assignment)?;
131 }
132 if version >= 4 {
133 let mut all_tags: Vec<RawTaggedField> = self._unknown_tagged_fields.clone();
134 all_tags.sort_by_key(|f| f.tag);
135 write_tagged_fields(buf, &all_tags)?;
136 }
137 Ok(())
138 }
139 pub fn encoded_len(&self, version: i16) -> Result<usize> {
140 if version < 0 || version > 5 {
141 return Err(UnsupportedVersion::new(14, version).into());
142 }
143 let mut len: usize = 0;
144 if version >= 1 {
145 len += 4;
146 } else if self.throttle_time_ms != 0_i32 {
147 return Err(UnsupportedFieldVersion::new(14, "throttle_time_ms", version).into());
148 }
149 len += 2;
150 if version >= 5 {
151 len += compact_nullable_string_len(self.protocol_type.as_ref())?;
152 } else if self.protocol_type != None {
153 return Err(UnsupportedFieldVersion::new(14, "protocol_type", version).into());
154 }
155 if version >= 5 {
156 len += compact_nullable_string_len(self.protocol_name.as_ref())?;
157 } else if self.protocol_name != None {
158 return Err(UnsupportedFieldVersion::new(14, "protocol_name", version).into());
159 }
160 if version >= 4 {
161 len += compact_bytes_len(&self.assignment)?;
162 } else {
163 len += bytes_len(&self.assignment)?;
164 }
165 if version >= 4 {
166 let mut all_tags: Vec<RawTaggedField> = self._unknown_tagged_fields.clone();
167 all_tags.sort_by_key(|f| f.tag);
168 len += tagged_fields_len(&all_tags)?;
169 }
170 Ok(len)
171 }
172}