crabka_protocol/opt/rustwide/workdir/generated/
OffsetForLeaderEpochResponse.owned.rs1use bytes::{Buf, BufMut};
4
5use crate::primitives::fixed::{get_i16, get_i32, get_i64, put_i16, put_i32, put_i64};
6use crate::primitives::string_bytes::{
7 compact_string_len, get_compact_string_owned, get_string_owned,
8 put_compact_string, put_string, string_len,
9};
10use crate::tagged_fields::{read_tagged_fields, tagged_fields_len, WriteTaggedFields};
11use crate::{Decode, Encode, ProtocolError, UnknownTaggedFields};
12
13pub const API_KEY: i16 = 23;
14pub const MIN_VERSION: i16 = 2;
15pub const MAX_VERSION: i16 = 4;
16pub const FLEXIBLE_MIN: i16 = 4;
17
18#[inline]
19fn is_flexible(version: i16) -> bool { version >= FLEXIBLE_MIN }
20
21#[derive(Debug, Clone, PartialEq, Eq, Default)]
22pub struct OffsetForLeaderEpochResponse {
23 pub throttle_time_ms: i32,
24 pub topics: Vec<OffsetForLeaderTopicResult>,
25 pub unknown_tagged_fields: UnknownTaggedFields,
26}
27
28impl Encode for OffsetForLeaderEpochResponse {
29 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
30 if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
31 return Err(ProtocolError::UnsupportedVersion { api_key: API_KEY, version });
32 }
33 let flex = is_flexible(version);
34 if version >= 2 { put_i32(buf, self.throttle_time_ms) }
35 if version >= 0 { { crate::primitives::array::put_array_len(buf, (self.topics).len(), flex); for it in &self.topics { it.encode(buf, version)?; } } }
36 if flex {
37 let tagged = WriteTaggedFields::new();
38 tagged.write(buf, &self.unknown_tagged_fields);
39 }
40 Ok(())
41 }
42 fn encoded_len(&self, version: i16) -> usize {
43 let flex = is_flexible(version);
44 let mut n: usize = 0;
45 if version >= 2 { n += 4; }
46 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 }; }
47 if flex {
48 let known_pairs: Vec<(u32, usize)> = Vec::new();
49 n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
50 }
51 n
52 }
53}
54
55impl<'de> Decode<'de> for OffsetForLeaderEpochResponse {
56 fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
57 if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
58 return Err(ProtocolError::UnsupportedVersion { api_key: API_KEY, version });
59 }
60 let flex = is_flexible(version);
61 let mut out = Self::default();
62 if version >= 2 { out.throttle_time_ms = get_i32(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(OffsetForLeaderTopicResult::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 OffsetForLeaderTopicResult {
75 pub topic: String,
76 pub partitions: Vec<EpochEndOffset>,
77 pub unknown_tagged_fields: UnknownTaggedFields,
78}
79
80impl Encode for OffsetForLeaderTopicResult {
81 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
82 let flex = version >= 4;
83 if version >= 0 { if flex { put_compact_string(buf, &self.topic) } else { put_string(buf, &self.topic) } }
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 >= 4;
93 let mut n: usize = 0;
94 if version >= 0 { n += if flex { compact_string_len(&self.topic) } else { string_len(&self.topic) }; }
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 OffsetForLeaderTopicResult {
105 fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
106 let flex = version >= 4;
107 let mut out = Self::default();
108 if version >= 0 { out.topic = if flex { get_compact_string_owned(buf)? } else { get_string_owned(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(EpochEndOffset::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)]
120pub struct EpochEndOffset {
121 pub error_code: i16,
122 pub partition: i32,
123 pub leader_epoch: i32,
124 pub end_offset: i64,
125 pub unknown_tagged_fields: UnknownTaggedFields,
126}
127
128impl Default for EpochEndOffset {
129 fn default() -> Self {
130 Self {
131 error_code: 0i16,
132 partition: 0i32,
133 leader_epoch: -1i32,
134 end_offset: -1i64,
135 unknown_tagged_fields: Default::default(),
136 }
137 }
138}
139
140impl Encode for EpochEndOffset {
141 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
142 let flex = version >= 4;
143 if version >= 0 { put_i16(buf, self.error_code) }
144 if version >= 0 { put_i32(buf, self.partition) }
145 if version >= 1 { put_i32(buf, self.leader_epoch) }
146 if version >= 0 { put_i64(buf, self.end_offset) }
147 if flex {
148 let tagged = WriteTaggedFields::new();
149 tagged.write(buf, &self.unknown_tagged_fields);
150 }
151 Ok(())
152 }
153 fn encoded_len(&self, version: i16) -> usize {
154 let flex = version >= 4;
155 let mut n: usize = 0;
156 if version >= 0 { n += 2; }
157 if version >= 0 { n += 4; }
158 if version >= 1 { n += 4; }
159 if version >= 0 { n += 8; }
160 if flex {
161 let known_pairs: Vec<(u32, usize)> = Vec::new();
162 n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
163 }
164 n
165 }
166}
167
168impl<'de> Decode<'de> for EpochEndOffset {
169 fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
170 let flex = version >= 4;
171 let mut out = Self::default();
172 if version >= 0 { out.error_code = get_i16(buf)?; }
173 if version >= 0 { out.partition = get_i32(buf)?; }
174 if version >= 1 { out.leader_epoch = get_i32(buf)?; }
175 if version >= 0 { out.end_offset = get_i64(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 if version >= 2 {
192 obj.insert("throttleTimeMs".to_string(), ::serde_json::json!(0));
193 }
194 obj.insert("topics".to_string(), ::serde_json::Value::Array(vec![]));
195 ::serde_json::Value::Object(obj)
196}