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