kafka_api/schemata/
produce_request.rs1use byteorder::ReadBytesExt;
16
17use crate::codec::*;
18use crate::IoResult;
19
20#[derive(Debug, Default, Clone)]
37pub struct ProduceRequest {
38 pub transactional_id: Option<String>,
40 pub acks: i16,
44 pub timeout_ms: i32,
46 pub topic_data: Vec<TopicProduceData>,
48 pub unknown_tagged_fields: Vec<RawTaggedField>,
50}
51
52impl Decodable for ProduceRequest {
53 fn read<B: ReadBytesExt>(buf: &mut B, version: i16) -> IoResult<Self> {
54 let mut this = ProduceRequest::default();
55 if version >= 3 {
56 this.transactional_id = NullableString(version >= 9).decode(buf)?;
57 }
58 this.acks = Int16.decode(buf)?;
59 this.timeout_ms = Int32.decode(buf)?;
60 this.topic_data = NullableArray(Struct(version), version >= 9)
61 .decode(buf)?
62 .ok_or_else(|| err_decode_message_null("topic_data"))?;
63 if version >= 9 {
64 this.unknown_tagged_fields = RawTaggedFieldList.decode(buf)?;
65 }
66 Ok(this)
67 }
68}
69
70#[derive(Debug, Default, Clone)]
71pub struct TopicProduceData {
72 pub name: String,
74 pub partition_data: Vec<PartitionProduceData>,
76 pub unknown_tagged_fields: Vec<RawTaggedField>,
78}
79
80impl Decodable for TopicProduceData {
81 fn read<B: ReadBytesExt>(buf: &mut B, version: i16) -> IoResult<Self> {
82 if version > 9 {
83 Err(err_decode_message_unsupported(version, "TopicProduceData"))?
84 }
85 let mut this = TopicProduceData {
86 name: NullableString(version >= 9)
87 .decode(buf)?
88 .ok_or_else(|| err_decode_message_null("name"))?,
89 partition_data: NullableArray(Struct(version), version >= 9)
90 .decode(buf)?
91 .ok_or_else(|| err_decode_message_null("partition_data"))?,
92 ..Default::default()
93 };
94 if version >= 9 {
95 this.unknown_tagged_fields = RawTaggedFieldList.decode(buf)?;
96 }
97 Ok(this)
98 }
99}
100
101#[derive(Debug, Default, Clone)]
102pub struct PartitionProduceData {
103 pub index: i32,
105 pub records: Option<Vec<u8>>,
107 pub unknown_tagged_fields: Vec<RawTaggedField>,
109}
110
111impl Decodable for PartitionProduceData {
112 fn read<B: ReadBytesExt>(buf: &mut B, version: i16) -> IoResult<Self> {
113 if version > 9 {
114 Err(err_decode_message_unsupported(
115 version,
116 "PartitionProduceData",
117 ))?
118 }
119 let mut this = PartitionProduceData {
120 index: Int32.decode(buf)?,
121 records: NullableBytes(version >= 9).decode(buf)?,
122 ..Default::default()
123 };
124 if version >= 9 {
125 this.unknown_tagged_fields = RawTaggedFieldList.decode(buf)?;
126 }
127 Ok(this)
128 }
129}