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