kafka_api/schemata/
produce_response.rs1use byteorder::WriteBytesExt;
16
17use crate::codec::*;
18use crate::IoResult;
19
20#[derive(Debug, Default, Clone)]
37pub struct ProduceResponse {
38 pub responses: Vec<TopicProduceResponse>,
40 pub throttle_time_ms: i32,
43 pub unknown_tagged_fields: Vec<RawTaggedField>,
45}
46
47impl Encodable for ProduceResponse {
48 fn write<B: WriteBytesExt>(&self, buf: &mut B, version: i16) -> IoResult<()> {
49 NullableArray(Struct(version), version >= 9).encode(buf, self.responses.as_slice())?;
50 if version > 1 {
51 Int32.encode(buf, self.throttle_time_ms)?;
52 }
53 if version >= 9 {
54 RawTaggedFieldList.encode(buf, &self.unknown_tagged_fields)?;
55 }
56 Ok(())
57 }
58
59 fn calculate_size(&self, version: i16) -> usize {
60 let mut res = 0;
61 res +=
62 NullableArray(Struct(version), version >= 9).calculate_size(self.responses.as_slice());
63 if version > 1 {
64 res += Int32::SIZE; }
66 if version >= 9 {
67 res += RawTaggedFieldList.calculate_size(&self.unknown_tagged_fields);
68 }
69 res
70 }
71}
72
73#[derive(Debug, Default, Clone)]
74pub struct TopicProduceResponse {
75 pub name: String,
77 pub partition_responses: Vec<PartitionProduceResponse>,
79 pub unknown_tagged_fields: Vec<RawTaggedField>,
81}
82
83impl Encodable for TopicProduceResponse {
84 fn write<B: WriteBytesExt>(&self, buf: &mut B, version: i16) -> IoResult<()> {
85 NullableString(version >= 9).encode(buf, self.name.as_str())?;
86 NullableArray(Struct(version), version >= 9)
87 .encode(buf, self.partition_responses.as_slice())?;
88 if version >= 9 {
89 RawTaggedFieldList.encode(buf, &self.unknown_tagged_fields)?;
90 }
91 Ok(())
92 }
93
94 fn calculate_size(&self, version: i16) -> usize {
95 let mut res = 0;
96 res += NullableString(version >= 9).calculate_size(self.name.as_str());
97 res += NullableArray(Struct(version), version >= 9)
98 .calculate_size(self.partition_responses.as_slice());
99 if version >= 9 {
100 res += RawTaggedFieldList.calculate_size(&self.unknown_tagged_fields);
101 }
102 res
103 }
104}
105
106#[derive(Debug, Default, Clone)]
107pub struct PartitionProduceResponse {
108 pub index: i32,
110 pub error_code: i16,
112 pub base_offset: i64,
114 pub log_append_time_ms: i64,
118 pub log_start_offset: i64,
120 pub record_errors: Vec<BatchIndexAndErrorMessage>,
122 pub error_message: Option<String>,
125 pub unknown_tagged_fields: Vec<RawTaggedField>,
127}
128
129impl Encodable for PartitionProduceResponse {
130 fn write<B: WriteBytesExt>(&self, buf: &mut B, version: i16) -> IoResult<()> {
131 Int32.encode(buf, self.index)?;
132 Int16.encode(buf, self.error_code)?;
133 Int64.encode(buf, self.base_offset)?;
134 if version >= 2 {
135 Int64.encode(buf, self.log_append_time_ms)?;
136 }
137 if version >= 5 {
138 Int64.encode(buf, self.log_start_offset)?;
139 }
140 if version >= 8 {
141 NullableArray(Struct(version), version >= 9)
142 .encode(buf, self.record_errors.as_slice())?;
143 }
144 if version >= 8 {
145 NullableString(version >= 9).encode(buf, self.error_message.as_deref())?;
146 }
147 if version >= 9 {
148 RawTaggedFieldList.encode(buf, &self.unknown_tagged_fields)?;
149 }
150 Ok(())
151 }
152
153 fn calculate_size(&self, version: i16) -> usize {
154 let mut res = 0;
155 res += Int32::SIZE; res += Int16::SIZE; res += Int64::SIZE; if version >= 2 {
159 res += Int64::SIZE; }
161 if version >= 5 {
162 res += Int64::SIZE; }
164 if version >= 8 {
165 res += NullableArray(Struct(version), version >= 9)
166 .calculate_size(self.record_errors.as_slice());
167 }
168 if version >= 8 {
169 res += NullableString(version >= 9).calculate_size(self.error_message.as_deref());
170 }
171 if version >= 9 {
172 res += RawTaggedFieldList.calculate_size(&self.unknown_tagged_fields);
173 }
174 res
175 }
176}
177
178#[derive(Debug, Default, Clone)]
179pub struct BatchIndexAndErrorMessage {
180 pub batch_index: i32,
182 pub batch_index_error_message: Option<String>,
184 pub unknown_tagged_fields: Vec<RawTaggedField>,
186}
187
188impl Encodable for BatchIndexAndErrorMessage {
189 fn write<B: WriteBytesExt>(&self, buf: &mut B, version: i16) -> IoResult<()> {
190 if version < 8 {
191 Err(err_encode_message_unsupported(
192 version,
193 "BatchIndexAndErrorMessage",
194 ))?
195 }
196 Int32.encode(buf, self.batch_index)?;
197 NullableString(version >= 9).encode(buf, self.batch_index_error_message.as_deref())?;
198 if version >= 9 {
199 RawTaggedFieldList.encode(buf, &self.unknown_tagged_fields)?;
200 }
201 Ok(())
202 }
203
204 fn calculate_size(&self, version: i16) -> usize {
205 let mut res = 0;
206 res += Int32::SIZE; res +=
208 NullableString(version >= 9).calculate_size(self.batch_index_error_message.as_deref());
209 if version >= 9 {
210 res += RawTaggedFieldList.calculate_size(&self.unknown_tagged_fields);
211 }
212 res
213 }
214}