Skip to main content

crabka_protocol/opt/rustwide/workdir/generated/
ListPartitionReassignmentsResponse.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_i16, get_i32, put_i16, put_i32};
6use crate::primitives::string_bytes::{
7    compact_nullable_string_len, compact_string_len, get_compact_nullable_string_owned,
8    get_compact_string_owned, get_nullable_string_owned, get_string_owned, nullable_string_len,
9    put_compact_nullable_string, put_compact_string, put_nullable_string, put_string,
10    string_len,
11};
12use crate::tagged_fields::{read_tagged_fields, tagged_fields_len, WriteTaggedFields};
13use crate::{Decode, Encode, ProtocolError, UnknownTaggedFields};
14
15pub const API_KEY: i16 = 46;
16pub const MIN_VERSION: i16 = 0;
17pub const MAX_VERSION: i16 = 0;
18pub const FLEXIBLE_MIN: i16 = 0;
19
20#[inline]
21fn is_flexible(version: i16) -> bool { version >= FLEXIBLE_MIN }
22
23#[derive(Debug, Clone, PartialEq, Eq, Default)]
24pub struct ListPartitionReassignmentsResponse {
25    pub throttle_time_ms: i32,
26    pub error_code: i16,
27    pub error_message: Option<String>,
28    pub topics: Vec<OngoingTopicReassignment>,
29    pub unknown_tagged_fields: UnknownTaggedFields,
30}
31
32impl Encode for ListPartitionReassignmentsResponse {
33    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
34        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
35            return Err(ProtocolError::UnsupportedVersion { api_key: API_KEY, version });
36        }
37        let flex = is_flexible(version);
38        if version >= 0 { put_i32(buf, self.throttle_time_ms) }
39        if version >= 0 { put_i16(buf, self.error_code) }
40        if version >= 0 { if flex { put_compact_nullable_string(buf, self.error_message.as_deref()) } else { put_nullable_string(buf, self.error_message.as_deref()) } }
41        if version >= 0 { { crate::primitives::array::put_array_len(buf, (self.topics).len(), flex); for it in &self.topics { it.encode(buf, version)?; } } }
42        if flex {
43            let tagged = WriteTaggedFields::new();
44            tagged.write(buf, &self.unknown_tagged_fields);
45        }
46        Ok(())
47    }
48    fn encoded_len(&self, version: i16) -> usize {
49        let flex = is_flexible(version);
50        let mut n: usize = 0;
51        if version >= 0 { n += 4; }
52        if version >= 0 { n += 2; }
53        if version >= 0 { n += if flex { compact_nullable_string_len(self.error_message.as_deref()) } else { nullable_string_len(self.error_message.as_deref()) }; }
54        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 }; }
55        if flex {
56            let known_pairs: Vec<(u32, usize)> = Vec::new();
57            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
58        }
59        n
60    }
61}
62
63impl<'de> Decode<'de> for ListPartitionReassignmentsResponse {
64    fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
65        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
66            return Err(ProtocolError::UnsupportedVersion { api_key: API_KEY, version });
67        }
68        let flex = is_flexible(version);
69        let mut out = Self::default();
70        if version >= 0 { out.throttle_time_ms = get_i32(buf)?; }
71        if version >= 0 { out.error_code = get_i16(buf)?; }
72        if version >= 0 { out.error_message = if flex { get_compact_nullable_string_owned(buf)? } else { get_nullable_string_owned(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(OngoingTopicReassignment::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 OngoingTopicReassignment {
85    pub name: String,
86    pub partitions: Vec<OngoingPartitionReassignment>,
87    pub unknown_tagged_fields: UnknownTaggedFields,
88}
89
90impl Encode for OngoingTopicReassignment {
91    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
92        let flex = version >= 0;
93        if version >= 0 { if flex { put_compact_string(buf, &self.name) } else { put_string(buf, &self.name) } }
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 >= 0;
103        let mut n: usize = 0;
104        if version >= 0 { n += if flex { compact_string_len(&self.name) } else { string_len(&self.name) }; }
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 OngoingTopicReassignment {
115    fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
116        let flex = version >= 0;
117        let mut out = Self::default();
118        if version >= 0 { out.name = 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(OngoingPartitionReassignment::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, Default)]
130pub struct OngoingPartitionReassignment {
131    pub partition_index: i32,
132    pub replicas: Vec<i32>,
133    pub adding_replicas: Vec<i32>,
134    pub removing_replicas: Vec<i32>,
135    pub unknown_tagged_fields: UnknownTaggedFields,
136}
137
138impl Encode for OngoingPartitionReassignment {
139    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
140        let flex = version >= 0;
141        if version >= 0 { put_i32(buf, self.partition_index) }
142        if version >= 0 { { crate::primitives::array::put_array_len(buf, (self.replicas).len(), flex); for it in &self.replicas { put_i32(buf, *it); } } }
143        if version >= 0 { { crate::primitives::array::put_array_len(buf, (self.adding_replicas).len(), flex); for it in &self.adding_replicas { put_i32(buf, *it); } } }
144        if version >= 0 { { crate::primitives::array::put_array_len(buf, (self.removing_replicas).len(), flex); for it in &self.removing_replicas { put_i32(buf, *it); } } }
145        if flex {
146            let tagged = WriteTaggedFields::new();
147            tagged.write(buf, &self.unknown_tagged_fields);
148        }
149        Ok(())
150    }
151    fn encoded_len(&self, version: i16) -> usize {
152        let flex = version >= 0;
153        let mut n: usize = 0;
154        if version >= 0 { n += 4; }
155        if version >= 0 { n += { let prefix = crate::primitives::array::array_len_prefix_len((self.replicas).len(), flex); let body: usize = (self.replicas).iter().map(|_| 4).sum(); prefix + body }; }
156        if version >= 0 { n += { let prefix = crate::primitives::array::array_len_prefix_len((self.adding_replicas).len(), flex); let body: usize = (self.adding_replicas).iter().map(|_| 4).sum(); prefix + body }; }
157        if version >= 0 { n += { let prefix = crate::primitives::array::array_len_prefix_len((self.removing_replicas).len(), flex); let body: usize = (self.removing_replicas).iter().map(|_| 4).sum(); prefix + body }; }
158        if flex {
159            let known_pairs: Vec<(u32, usize)> = Vec::new();
160            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
161        }
162        n
163    }
164}
165
166impl<'de> Decode<'de> for OngoingPartitionReassignment {
167    fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
168        let flex = version >= 0;
169        let mut out = Self::default();
170        if version >= 0 { out.partition_index = get_i32(buf)?; }
171        if version >= 0 { out.replicas = { let n = crate::primitives::array::get_array_len(buf, flex)?; let mut v = Vec::with_capacity(n); for _ in 0..n { v.push(get_i32(buf)?); } v }; }
172        if version >= 0 { out.adding_replicas = { let n = crate::primitives::array::get_array_len(buf, flex)?; let mut v = Vec::with_capacity(n); for _ in 0..n { v.push(get_i32(buf)?); } v }; }
173        if version >= 0 { out.removing_replicas = { let n = crate::primitives::array::get_array_len(buf, flex)?; let mut v = Vec::with_capacity(n); for _ in 0..n { v.push(get_i32(buf)?); } v }; }
174        if flex {
175            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| {
176                Ok(false)
177            })?;
178        }
179        Ok(out)
180    }
181}
182
183/// Default JSON payload matching `Self::default()` for JVM oracle differential testing.
184/// Only includes fields valid for the given version.
185#[must_use]
186#[allow(unused_comparisons)]
187pub fn default_json(version: i16) -> ::serde_json::Value {
188    let mut obj = ::serde_json::Map::new();
189    obj.insert("throttleTimeMs".to_string(), ::serde_json::json!(0));
190    obj.insert("errorCode".to_string(), ::serde_json::json!(0));
191    obj.insert("errorMessage".to_string(), ::serde_json::Value::Null);
192    obj.insert("topics".to_string(), ::serde_json::Value::Array(vec![]));
193    ::serde_json::Value::Object(obj)
194}