Skip to main content

krabka_protocol/opt/rustwide/workdir/generated/
GetReplicaLogInfoRequest.owned.rs

1// AUTO-GENERATED by krabka-protocol-codegen against a9ce3221537b8653448750697915607dc7936cf3. Do not edit.
2
3use bytes::{Buf, BufMut};
4
5use crate::{
6    Decode, Encode, ProtocolError, UnknownTaggedFields,
7    primitives::fixed::{get_i32, put_i32},
8    tagged_fields::{WriteTaggedFields, read_tagged_fields, tagged_fields_len},
9};
10pub const API_KEY: i16 = 1020;
11pub const MIN_VERSION: i16 = 0;
12pub const MAX_VERSION: i16 = 0;
13pub const LATEST_STABLE_VERSION: i16 = 0;
14pub const FLEXIBLE_MIN: i16 = 0;
15#[inline]
16#[must_use]
17pub fn is_flexible(version: i16) -> bool {
18    version >= FLEXIBLE_MIN
19}
20#[derive(Debug, Clone, PartialEq, Eq, Default)]
21pub struct GetReplicaLogInfoRequest {
22    pub broker_id: i32,
23    pub topic_partitions: Vec<TopicPartitions>,
24    pub unknown_tagged_fields: UnknownTaggedFields,
25}
26impl Encode for GetReplicaLogInfoRequest {
27    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
28        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
29            return Err(ProtocolError::UnsupportedVersion {
30                api_key: API_KEY,
31                version,
32            });
33        }
34        let flex = is_flexible(version);
35        if version >= 0 {
36            put_i32(buf, self.broker_id);
37        }
38        if version >= 0 {
39            {
40                crate::primitives::array::put_array_len(buf, (self.topic_partitions).len(), flex);
41                for it in &self.topic_partitions {
42                    it.encode(buf, version)?;
43                }
44            };
45        }
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 >= 0 {
56            n += 4;
57        }
58        if version >= 0 {
59            n += {
60                let prefix = crate::primitives::array::array_len_prefix_len(
61                    (self.topic_partitions).len(),
62                    flex,
63                );
64                let body: usize = (self.topic_partitions)
65                    .iter()
66                    .map(|it| it.encoded_len(version))
67                    .sum();
68                prefix + body
69            };
70        }
71        if flex {
72            let known_pairs: Vec<(u32, usize)> = Vec::new();
73            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
74        }
75        n
76    }
77}
78impl Decode<'_> for GetReplicaLogInfoRequest {
79    fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
80        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
81            return Err(ProtocolError::UnsupportedVersion {
82                api_key: API_KEY,
83                version,
84            });
85        }
86        let flex = is_flexible(version);
87        let mut out = Self::default();
88        if version >= 0 {
89            out.broker_id = get_i32(buf)?;
90        }
91        if version >= 0 {
92            out.topic_partitions = {
93                let n = crate::primitives::array::get_array_len(buf, flex)?;
94                let mut v = Vec::with_capacity(n);
95                for _ in 0..n {
96                    v.push(TopicPartitions::decode(buf, version)?);
97                }
98                v
99            };
100        }
101        if flex {
102            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
103        }
104        Ok(out)
105    }
106}
107#[cfg(test)]
108impl GetReplicaLogInfoRequest {
109    #[must_use]
110    pub fn populated(version: i16) -> Self {
111        let mut m = Self::default();
112        if version >= 0 {
113            m.broker_id = 1i32;
114        }
115        if version >= 0 {
116            m.topic_partitions = vec![TopicPartitions::populated(version)];
117        }
118        m
119    }
120}
121#[derive(Debug, Clone, PartialEq, Eq, Default)]
122pub struct TopicPartitions {
123    pub topic_id: crate::primitives::uuid::Uuid,
124    pub partitions: Vec<i32>,
125    pub unknown_tagged_fields: UnknownTaggedFields,
126}
127impl Encode for TopicPartitions {
128    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
129        let flex = version >= 0;
130        if version >= 0 {
131            crate::primitives::uuid::put_uuid(buf, self.topic_id);
132        }
133        if version >= 0 {
134            {
135                crate::primitives::array::put_array_len(buf, (self.partitions).len(), flex);
136                for it in &self.partitions {
137                    put_i32(buf, *it);
138                }
139            };
140        }
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 {
151            n += 16;
152        }
153        if version >= 0 {
154            n += {
155                let prefix =
156                    crate::primitives::array::array_len_prefix_len((self.partitions).len(), flex);
157                let body: usize = (self.partitions).iter().map(|_| 4).sum();
158                prefix + body
159            };
160        }
161        if flex {
162            let known_pairs: Vec<(u32, usize)> = Vec::new();
163            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
164        }
165        n
166    }
167}
168impl Decode<'_> for TopicPartitions {
169    fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
170        let flex = version >= 0;
171        let mut out = Self::default();
172        if version >= 0 {
173            out.topic_id = crate::primitives::uuid::get_uuid(buf)?;
174        }
175        if version >= 0 {
176            out.partitions = {
177                let n = crate::primitives::array::get_array_len(buf, flex)?;
178                let mut v = Vec::with_capacity(n);
179                for _ in 0..n {
180                    v.push(get_i32(buf)?);
181                }
182                v
183            };
184        }
185        if flex {
186            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
187        }
188        Ok(out)
189    }
190}
191#[cfg(test)]
192impl TopicPartitions {
193    #[must_use]
194    pub fn populated(version: i16) -> Self {
195        let mut m = Self::default();
196        if version >= 0 {
197            m.topic_id = crate::primitives::uuid::Uuid([1u8; 16]);
198        }
199        if version >= 0 {
200            m.partitions = vec![1i32];
201        }
202        m
203    }
204}
205/// Default JSON payload matching `Self::default()` for JVM oracle differential testing.
206/// Only includes fields valid for the given version.
207#[must_use]
208#[allow(unused_comparisons)]
209pub fn default_json(_version: i16) -> ::serde_json::Value {
210    let mut obj = ::serde_json::Map::new();
211    obj.insert("brokerId".to_string(), ::serde_json::json!(0));
212    obj.insert(
213        "topicPartitions".to_string(),
214        ::serde_json::Value::Array(vec![]),
215    );
216    ::serde_json::Value::Object(obj)
217}
218impl crate::ProtocolRequest for GetReplicaLogInfoRequest {
219    const API_KEY: i16 = API_KEY;
220    const MIN_VERSION: i16 = MIN_VERSION;
221    const MAX_VERSION: i16 = MAX_VERSION;
222    const LATEST_STABLE_VERSION: i16 = LATEST_STABLE_VERSION;
223    const FLEXIBLE_MIN: i16 = FLEXIBLE_MIN;
224    type Response = super::get_replica_log_info_response::GetReplicaLogInfoResponse;
225}