crabka_protocol/opt/rustwide/workdir/generated/
AlterPartitionResponse.owned.rs1use bytes::{Buf, BufMut};
4
5use crate::primitives::fixed::{get_i16, get_i32, get_i8, put_i16, put_i32, put_i8};
6use crate::tagged_fields::{read_tagged_fields, tagged_fields_len, WriteTaggedFields};
7use crate::{Decode, Encode, ProtocolError, UnknownTaggedFields};
8
9pub const API_KEY: i16 = 56;
10pub const MIN_VERSION: i16 = 2;
11pub const MAX_VERSION: i16 = 3;
12pub const FLEXIBLE_MIN: i16 = 0;
13
14#[inline]
15fn is_flexible(version: i16) -> bool { version >= FLEXIBLE_MIN }
16
17#[derive(Debug, Clone, PartialEq, Eq, Default)]
18pub struct AlterPartitionResponse {
19 pub throttle_time_ms: i32,
20 pub error_code: i16,
21 pub topics: Vec<TopicData>,
22 pub unknown_tagged_fields: UnknownTaggedFields,
23}
24
25impl Encode for AlterPartitionResponse {
26 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
27 if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
28 return Err(ProtocolError::UnsupportedVersion { api_key: API_KEY, version });
29 }
30 let flex = is_flexible(version);
31 if version >= 0 { put_i32(buf, self.throttle_time_ms) }
32 if version >= 0 { put_i16(buf, self.error_code) }
33 if version >= 0 { { crate::primitives::array::put_array_len(buf, (self.topics).len(), flex); for it in &self.topics { it.encode(buf, version)?; } } }
34 if flex {
35 let tagged = WriteTaggedFields::new();
36 tagged.write(buf, &self.unknown_tagged_fields);
37 }
38 Ok(())
39 }
40 fn encoded_len(&self, version: i16) -> usize {
41 let flex = is_flexible(version);
42 let mut n: usize = 0;
43 if version >= 0 { n += 4; }
44 if version >= 0 { n += 2; }
45 if version >= 0 { n += { let prefix = crate::primitives::array::array_len_prefix_len((self.topics).len(), flex); let body: usize = (self.topics).iter().map(|it| it.encoded_len(version)).sum(); prefix + body }; }
46 if flex {
47 let known_pairs: Vec<(u32, usize)> = Vec::new();
48 n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
49 }
50 n
51 }
52}
53
54impl<'de> Decode<'de> for AlterPartitionResponse {
55 fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
56 if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
57 return Err(ProtocolError::UnsupportedVersion { api_key: API_KEY, version });
58 }
59 let flex = is_flexible(version);
60 let mut out = Self::default();
61 if version >= 0 { out.throttle_time_ms = get_i32(buf)?; }
62 if version >= 0 { out.error_code = get_i16(buf)?; }
63 if version >= 0 { out.topics = { let n = crate::primitives::array::get_array_len(buf, flex)?; let mut v = Vec::with_capacity(n); for _ in 0..n { v.push(TopicData::decode(buf, version)?); } v }; }
64 if flex {
65 out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| {
66 Ok(false)
67 })?;
68 }
69 Ok(out)
70 }
71}
72
73#[derive(Debug, Clone, PartialEq, Eq, Default)]
74pub struct TopicData {
75 pub topic_id: crate::primitives::uuid::Uuid,
76 pub partitions: Vec<PartitionData>,
77 pub unknown_tagged_fields: UnknownTaggedFields,
78}
79
80impl Encode for TopicData {
81 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
82 let flex = version >= 0;
83 if version >= 2 { crate::primitives::uuid::put_uuid(buf, self.topic_id) }
84 if version >= 0 { { crate::primitives::array::put_array_len(buf, (self.partitions).len(), flex); for it in &self.partitions { it.encode(buf, version)?; } } }
85 if flex {
86 let tagged = WriteTaggedFields::new();
87 tagged.write(buf, &self.unknown_tagged_fields);
88 }
89 Ok(())
90 }
91 fn encoded_len(&self, version: i16) -> usize {
92 let flex = version >= 0;
93 let mut n: usize = 0;
94 if version >= 2 { n += 16; }
95 if version >= 0 { n += { let prefix = crate::primitives::array::array_len_prefix_len((self.partitions).len(), flex); let body: usize = (self.partitions).iter().map(|it| it.encoded_len(version)).sum(); prefix + body }; }
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}
103
104impl<'de> Decode<'de> for TopicData {
105 fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
106 let flex = version >= 0;
107 let mut out = Self::default();
108 if version >= 2 { out.topic_id = crate::primitives::uuid::get_uuid(buf)?; }
109 if version >= 0 { out.partitions = { let n = crate::primitives::array::get_array_len(buf, flex)?; let mut v = Vec::with_capacity(n); for _ in 0..n { v.push(PartitionData::decode(buf, version)?); } v }; }
110 if flex {
111 out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| {
112 Ok(false)
113 })?;
114 }
115 Ok(out)
116 }
117}
118
119#[derive(Debug, Clone, PartialEq, Eq, Default)]
120pub struct PartitionData {
121 pub partition_index: i32,
122 pub error_code: i16,
123 pub leader_id: i32,
124 pub leader_epoch: i32,
125 pub isr: Vec<i32>,
126 pub leader_recovery_state: i8,
127 pub partition_epoch: i32,
128 pub unknown_tagged_fields: UnknownTaggedFields,
129}
130
131impl Encode for PartitionData {
132 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
133 let flex = version >= 0;
134 if version >= 0 { put_i32(buf, self.partition_index) }
135 if version >= 0 { put_i16(buf, self.error_code) }
136 if version >= 0 { put_i32(buf, self.leader_id) }
137 if version >= 0 { put_i32(buf, self.leader_epoch) }
138 if version >= 0 { { crate::primitives::array::put_array_len(buf, (self.isr).len(), flex); for it in &self.isr { put_i32(buf, *it); } } }
139 if version >= 1 { put_i8(buf, self.leader_recovery_state) }
140 if version >= 0 { put_i32(buf, self.partition_epoch) }
141 if flex {
142 let tagged = WriteTaggedFields::new();
143 tagged.write(buf, &self.unknown_tagged_fields);
144 }
145 Ok(())
146 }
147 fn encoded_len(&self, version: i16) -> usize {
148 let flex = version >= 0;
149 let mut n: usize = 0;
150 if version >= 0 { n += 4; }
151 if version >= 0 { n += 2; }
152 if version >= 0 { n += 4; }
153 if version >= 0 { n += 4; }
154 if version >= 0 { n += { let prefix = crate::primitives::array::array_len_prefix_len((self.isr).len(), flex); let body: usize = (self.isr).iter().map(|_| 4).sum(); prefix + body }; }
155 if version >= 1 { n += 1; }
156 if version >= 0 { n += 4; }
157 if flex {
158 let known_pairs: Vec<(u32, usize)> = Vec::new();
159 n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
160 }
161 n
162 }
163}
164
165impl<'de> Decode<'de> for PartitionData {
166 fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
167 let flex = version >= 0;
168 let mut out = Self::default();
169 if version >= 0 { out.partition_index = get_i32(buf)?; }
170 if version >= 0 { out.error_code = get_i16(buf)?; }
171 if version >= 0 { out.leader_id = get_i32(buf)?; }
172 if version >= 0 { out.leader_epoch = get_i32(buf)?; }
173 if version >= 0 { out.isr = { let n = crate::primitives::array::get_array_len(buf, flex)?; let mut v = Vec::with_capacity(n); for _ in 0..n { v.push(get_i32(buf)?); } v }; }
174 if version >= 1 { out.leader_recovery_state = get_i8(buf)?; }
175 if version >= 0 { out.partition_epoch = get_i32(buf)?; }
176 if flex {
177 out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| {
178 Ok(false)
179 })?;
180 }
181 Ok(out)
182 }
183}
184
185#[must_use]
188#[allow(unused_comparisons)]
189pub fn default_json(version: i16) -> ::serde_json::Value {
190 let mut obj = ::serde_json::Map::new();
191 obj.insert("throttleTimeMs".to_string(), ::serde_json::json!(0));
192 obj.insert("errorCode".to_string(), ::serde_json::json!(0));
193 obj.insert("topics".to_string(), ::serde_json::Value::Array(vec![]));
194 ::serde_json::Value::Object(obj)
195}