Skip to main content

crabka_protocol/opt/rustwide/workdir/generated/
GetReplicaLogInfoRequest.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::tagged_fields::{WriteTaggedFields, read_tagged_fields, tagged_fields_len};
7use crate::{Decode, Encode, ProtocolError, UnknownTaggedFields};
8
9pub const API_KEY: i16 = 93;
10pub const MIN_VERSION: i16 = 0;
11pub const MAX_VERSION: i16 = 0;
12pub const FLEXIBLE_MIN: i16 = 0;
13
14#[inline]
15fn is_flexible(version: i16) -> bool {
16    version >= FLEXIBLE_MIN
17}
18
19#[derive(Debug, Clone, PartialEq, Eq, Default)]
20pub struct GetReplicaLogInfoRequest {
21    pub broker_id: i32,
22    pub topic_partitions: Vec<TopicPartitions>,
23    pub unknown_tagged_fields: UnknownTaggedFields,
24}
25impl Encode for GetReplicaLogInfoRequest {
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 {
29                api_key: API_KEY,
30                version,
31            });
32        }
33        let flex = is_flexible(version);
34        if version >= 0 {
35            put_i32(buf, self.broker_id);
36        }
37        if version >= 0 {
38            {
39                crate::primitives::array::put_array_len(buf, (self.topic_partitions).len(), flex);
40                for it in &self.topic_partitions {
41                    it.encode(buf, version)?;
42                }
43            }
44        }
45        if flex {
46            let tagged = WriteTaggedFields::new();
47            tagged.write(buf, &self.unknown_tagged_fields);
48        }
49        Ok(())
50    }
51    fn encoded_len(&self, version: i16) -> usize {
52        let flex = is_flexible(version);
53        let mut n: usize = 0;
54        if version >= 0 {
55            n += 4;
56        }
57        if version >= 0 {
58            n += {
59                let prefix = crate::primitives::array::array_len_prefix_len(
60                    (self.topic_partitions).len(),
61                    flex,
62                );
63                let body: usize = (self.topic_partitions)
64                    .iter()
65                    .map(|it| it.encoded_len(version))
66                    .sum();
67                prefix + body
68            };
69        }
70        if flex {
71            let known_pairs: Vec<(u32, usize)> = Vec::new();
72            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
73        }
74        n
75    }
76}
77impl Decode<'_> for GetReplicaLogInfoRequest {
78    fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
79        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
80            return Err(ProtocolError::UnsupportedVersion {
81                api_key: API_KEY,
82                version,
83            });
84        }
85        let flex = is_flexible(version);
86        let mut out = Self::default();
87        if version >= 0 {
88            out.broker_id = get_i32(buf)?;
89        }
90        if version >= 0 {
91            out.topic_partitions = {
92                let n = crate::primitives::array::get_array_len(buf, flex)?;
93                let mut v = Vec::with_capacity(n);
94                for _ in 0..n {
95                    v.push(TopicPartitions::decode(buf, version)?);
96                }
97                v
98            };
99        }
100        if flex {
101            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
102        }
103        Ok(out)
104    }
105}
106#[cfg(test)]
107impl GetReplicaLogInfoRequest {
108    #[must_use]
109    pub fn populated(version: i16) -> Self {
110        let mut m = Self::default();
111        if version >= 0 {
112            m.broker_id = 1i32;
113        }
114        if version >= 0 {
115            m.topic_partitions = vec![TopicPartitions::populated(version)];
116        }
117        m
118    }
119}
120#[derive(Debug, Clone, PartialEq, Eq, Default)]
121pub struct TopicPartitions {
122    pub topic_id: crate::primitives::uuid::Uuid,
123    pub partitions: Vec<i32>,
124    pub unknown_tagged_fields: UnknownTaggedFields,
125}
126impl Encode for TopicPartitions {
127    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
128        let flex = version >= 0;
129        if version >= 0 {
130            crate::primitives::uuid::put_uuid(buf, self.topic_id);
131        }
132        if version >= 0 {
133            {
134                crate::primitives::array::put_array_len(buf, (self.partitions).len(), flex);
135                for it in &self.partitions {
136                    put_i32(buf, *it);
137                }
138            }
139        }
140        if flex {
141            let tagged = WriteTaggedFields::new();
142            tagged.write(buf, &self.unknown_tagged_fields);
143        }
144        Ok(())
145    }
146    fn encoded_len(&self, version: i16) -> usize {
147        let flex = version >= 0;
148        let mut n: usize = 0;
149        if version >= 0 {
150            n += 16;
151        }
152        if version >= 0 {
153            n += {
154                let prefix =
155                    crate::primitives::array::array_len_prefix_len((self.partitions).len(), flex);
156                let body: usize = (self.partitions).iter().map(|_| 4).sum();
157                prefix + body
158            };
159        }
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}
167impl Decode<'_> for TopicPartitions {
168    fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
169        let flex = version >= 0;
170        let mut out = Self::default();
171        if version >= 0 {
172            out.topic_id = crate::primitives::uuid::get_uuid(buf)?;
173        }
174        if version >= 0 {
175            out.partitions = {
176                let n = crate::primitives::array::get_array_len(buf, flex)?;
177                let mut v = Vec::with_capacity(n);
178                for _ in 0..n {
179                    v.push(get_i32(buf)?);
180                }
181                v
182            };
183        }
184        if flex {
185            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
186        }
187        Ok(out)
188    }
189}
190#[cfg(test)]
191impl TopicPartitions {
192    #[must_use]
193    pub fn populated(version: i16) -> Self {
194        let mut m = Self::default();
195        if version >= 0 {
196            m.topic_id = crate::primitives::uuid::Uuid([1u8; 16]);
197        }
198        if version >= 0 {
199            m.partitions = vec![1i32];
200        }
201        m
202    }
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}
218
219impl crate::ProtocolRequest for GetReplicaLogInfoRequest {
220    const API_KEY: i16 = API_KEY;
221    const MIN_VERSION: i16 = MIN_VERSION;
222    const MAX_VERSION: i16 = MAX_VERSION;
223    const FLEXIBLE_MIN: i16 = FLEXIBLE_MIN;
224    type Response = super::get_replica_log_info_response::GetReplicaLogInfoResponse;
225}