Skip to main content

crabka_protocol/opt/rustwide/workdir/generated/
OffsetForLeaderEpochRequest.owned.rs

1// AUTO-GENERATED by crabka-protocol-codegen against a9ce3221537b8653448750697915607dc7936cf3. Do not edit.
2
3use bytes::{Buf, BufMut};
4
5use crate::primitives::fixed::{get_i32, put_i32};
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)]
22pub struct OffsetForLeaderEpochRequest {
23    pub replica_id: i32,
24    pub topics: Vec<OffsetForLeaderTopic>,
25    pub unknown_tagged_fields: UnknownTaggedFields,
26}
27
28impl Default for OffsetForLeaderEpochRequest {
29    fn default() -> Self {
30        Self {
31            replica_id: -2i32,
32            topics: Vec::new(),
33            unknown_tagged_fields: Default::default(),
34        }
35    }
36}
37
38impl Encode for OffsetForLeaderEpochRequest {
39    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
40        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
41            return Err(ProtocolError::UnsupportedVersion { api_key: API_KEY, version });
42        }
43        let flex = is_flexible(version);
44        if version >= 3 { put_i32(buf, self.replica_id) }
45        if version >= 0 { { crate::primitives::array::put_array_len(buf, (self.topics).len(), flex); for it in &self.topics { it.encode(buf, version)?; } } }
46        if flex {
47            let tagged = WriteTaggedFields::new();
48            tagged.write(buf, &self.unknown_tagged_fields);
49        }
50        Ok(())
51    }
52    fn encoded_len(&self, version: i16) -> usize {
53        let flex = is_flexible(version);
54        let mut n: usize = 0;
55        if version >= 3 { n += 4; }
56        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 }; }
57        if flex {
58            let known_pairs: Vec<(u32, usize)> = Vec::new();
59            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
60        }
61        n
62    }
63}
64
65impl<'de> Decode<'de> for OffsetForLeaderEpochRequest {
66    fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
67        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
68            return Err(ProtocolError::UnsupportedVersion { api_key: API_KEY, version });
69        }
70        let flex = is_flexible(version);
71        let mut out = Self::default();
72        if version >= 3 { out.replica_id = get_i32(buf)?; }
73        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(OffsetForLeaderTopic::decode(buf, version)?); } v }; }
74        if flex {
75            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| {
76                Ok(false)
77            })?;
78        }
79        Ok(out)
80    }
81}
82
83#[derive(Debug, Clone, PartialEq, Eq, Default)]
84pub struct OffsetForLeaderTopic {
85    pub topic: String,
86    pub partitions: Vec<OffsetForLeaderPartition>,
87    pub unknown_tagged_fields: UnknownTaggedFields,
88}
89
90impl Encode for OffsetForLeaderTopic {
91    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
92        let flex = version >= 4;
93        if version >= 0 { if flex { put_compact_string(buf, &self.topic) } else { put_string(buf, &self.topic) } }
94        if version >= 0 { { crate::primitives::array::put_array_len(buf, (self.partitions).len(), flex); for it in &self.partitions { it.encode(buf, version)?; } } }
95        if flex {
96            let tagged = WriteTaggedFields::new();
97            tagged.write(buf, &self.unknown_tagged_fields);
98        }
99        Ok(())
100    }
101    fn encoded_len(&self, version: i16) -> usize {
102        let flex = version >= 4;
103        let mut n: usize = 0;
104        if version >= 0 { n += if flex { compact_string_len(&self.topic) } else { string_len(&self.topic) }; }
105        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 }; }
106        if flex {
107            let known_pairs: Vec<(u32, usize)> = Vec::new();
108            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
109        }
110        n
111    }
112}
113
114impl<'de> Decode<'de> for OffsetForLeaderTopic {
115    fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
116        let flex = version >= 4;
117        let mut out = Self::default();
118        if version >= 0 { out.topic = if flex { get_compact_string_owned(buf)? } else { get_string_owned(buf)? }; }
119        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(OffsetForLeaderPartition::decode(buf, version)?); } v }; }
120        if flex {
121            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| {
122                Ok(false)
123            })?;
124        }
125        Ok(out)
126    }
127}
128
129#[derive(Debug, Clone, PartialEq, Eq)]
130pub struct OffsetForLeaderPartition {
131    pub partition: i32,
132    pub current_leader_epoch: i32,
133    pub leader_epoch: i32,
134    pub unknown_tagged_fields: UnknownTaggedFields,
135}
136
137impl Default for OffsetForLeaderPartition {
138    fn default() -> Self {
139        Self {
140            partition: 0i32,
141            current_leader_epoch: -1i32,
142            leader_epoch: 0i32,
143            unknown_tagged_fields: Default::default(),
144        }
145    }
146}
147
148impl Encode for OffsetForLeaderPartition {
149    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
150        let flex = version >= 4;
151        if version >= 0 { put_i32(buf, self.partition) }
152        if version >= 2 { put_i32(buf, self.current_leader_epoch) }
153        if version >= 0 { put_i32(buf, self.leader_epoch) }
154        if flex {
155            let tagged = WriteTaggedFields::new();
156            tagged.write(buf, &self.unknown_tagged_fields);
157        }
158        Ok(())
159    }
160    fn encoded_len(&self, version: i16) -> usize {
161        let flex = version >= 4;
162        let mut n: usize = 0;
163        if version >= 0 { n += 4; }
164        if version >= 2 { n += 4; }
165        if version >= 0 { n += 4; }
166        if flex {
167            let known_pairs: Vec<(u32, usize)> = Vec::new();
168            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
169        }
170        n
171    }
172}
173
174impl<'de> Decode<'de> for OffsetForLeaderPartition {
175    fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
176        let flex = version >= 4;
177        let mut out = Self::default();
178        if version >= 0 { out.partition = get_i32(buf)?; }
179        if version >= 2 { out.current_leader_epoch = get_i32(buf)?; }
180        if version >= 0 { out.leader_epoch = get_i32(buf)?; }
181        if flex {
182            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| {
183                Ok(false)
184            })?;
185        }
186        Ok(out)
187    }
188}
189
190/// Default JSON payload matching `Self::default()` for JVM oracle differential testing.
191/// Only includes fields valid for the given version.
192#[must_use]
193#[allow(unused_comparisons)]
194pub fn default_json(version: i16) -> ::serde_json::Value {
195    let mut obj = ::serde_json::Map::new();
196    if version >= 3 {
197        obj.insert("replicaId".to_string(), ::serde_json::json!(-2));
198    }
199    obj.insert("topics".to_string(), ::serde_json::Value::Array(vec![]));
200    ::serde_json::Value::Object(obj)
201}
202
203impl crate::ProtocolRequest for OffsetForLeaderEpochRequest {
204    const API_KEY: i16 = API_KEY;
205    const MIN_VERSION: i16 = MIN_VERSION;
206    const MAX_VERSION: i16 = MAX_VERSION;
207    const FLEXIBLE_MIN: i16 = FLEXIBLE_MIN;
208    type Response = super::offset_for_leader_epoch_response::OffsetForLeaderEpochResponse;
209}