Skip to main content

crabka_protocol/opt/rustwide/workdir/generated/
AlterPartitionReassignmentsResponse.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_bool, get_i16, get_i32, put_bool, 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 = 45;
16pub const MIN_VERSION: i16 = 0;
17pub const MAX_VERSION: i16 = 1;
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)]
24pub struct AlterPartitionReassignmentsResponse {
25    pub throttle_time_ms: i32,
26    pub allow_replication_factor_change: bool,
27    pub error_code: i16,
28    pub error_message: Option<String>,
29    pub responses: Vec<ReassignableTopicResponse>,
30    pub unknown_tagged_fields: UnknownTaggedFields,
31}
32
33impl Default for AlterPartitionReassignmentsResponse {
34    fn default() -> Self {
35        Self {
36            throttle_time_ms: 0i32,
37            allow_replication_factor_change: true,
38            error_code: 0i16,
39            error_message: None,
40            responses: Vec::new(),
41            unknown_tagged_fields: Default::default(),
42        }
43    }
44}
45
46impl Encode for AlterPartitionReassignmentsResponse {
47    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
48        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
49            return Err(ProtocolError::UnsupportedVersion { api_key: API_KEY, version });
50        }
51        let flex = is_flexible(version);
52        if version >= 0 { put_i32(buf, self.throttle_time_ms) }
53        if version >= 1 { put_bool(buf, self.allow_replication_factor_change) }
54        if version >= 0 { put_i16(buf, self.error_code) }
55        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()) } }
56        if version >= 0 { { crate::primitives::array::put_array_len(buf, (self.responses).len(), flex); for it in &self.responses { it.encode(buf, version)?; } } }
57        if flex {
58            let tagged = WriteTaggedFields::new();
59            tagged.write(buf, &self.unknown_tagged_fields);
60        }
61        Ok(())
62    }
63    fn encoded_len(&self, version: i16) -> usize {
64        let flex = is_flexible(version);
65        let mut n: usize = 0;
66        if version >= 0 { n += 4; }
67        if version >= 1 { n += 1; }
68        if version >= 0 { n += 2; }
69        if version >= 0 { n += if flex { compact_nullable_string_len(self.error_message.as_deref()) } else { nullable_string_len(self.error_message.as_deref()) }; }
70        if version >= 0 { n += { let prefix = crate::primitives::array::array_len_prefix_len((self.responses).len(), flex); let body: usize = (self.responses).iter().map(|it| it.encoded_len(version)).sum(); prefix + body }; }
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}
78
79impl<'de> Decode<'de> for AlterPartitionReassignmentsResponse {
80    fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
81        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
82            return Err(ProtocolError::UnsupportedVersion { api_key: API_KEY, version });
83        }
84        let flex = is_flexible(version);
85        let mut out = Self::default();
86        if version >= 0 { out.throttle_time_ms = get_i32(buf)?; }
87        if version >= 1 { out.allow_replication_factor_change = get_bool(buf)?; }
88        if version >= 0 { out.error_code = get_i16(buf)?; }
89        if version >= 0 { out.error_message = if flex { get_compact_nullable_string_owned(buf)? } else { get_nullable_string_owned(buf)? }; }
90        if version >= 0 { out.responses = { let n = crate::primitives::array::get_array_len(buf, flex)?; let mut v = Vec::with_capacity(n); for _ in 0..n { v.push(ReassignableTopicResponse::decode(buf, version)?); } v }; }
91        if flex {
92            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| {
93                Ok(false)
94            })?;
95        }
96        Ok(out)
97    }
98}
99
100#[derive(Debug, Clone, PartialEq, Eq, Default)]
101pub struct ReassignableTopicResponse {
102    pub name: String,
103    pub partitions: Vec<ReassignablePartitionResponse>,
104    pub unknown_tagged_fields: UnknownTaggedFields,
105}
106
107impl Encode for ReassignableTopicResponse {
108    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
109        let flex = version >= 0;
110        if version >= 0 { if flex { put_compact_string(buf, &self.name) } else { put_string(buf, &self.name) } }
111        if version >= 0 { { crate::primitives::array::put_array_len(buf, (self.partitions).len(), flex); for it in &self.partitions { it.encode(buf, version)?; } } }
112        if flex {
113            let tagged = WriteTaggedFields::new();
114            tagged.write(buf, &self.unknown_tagged_fields);
115        }
116        Ok(())
117    }
118    fn encoded_len(&self, version: i16) -> usize {
119        let flex = version >= 0;
120        let mut n: usize = 0;
121        if version >= 0 { n += if flex { compact_string_len(&self.name) } else { string_len(&self.name) }; }
122        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 }; }
123        if flex {
124            let known_pairs: Vec<(u32, usize)> = Vec::new();
125            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
126        }
127        n
128    }
129}
130
131impl<'de> Decode<'de> for ReassignableTopicResponse {
132    fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
133        let flex = version >= 0;
134        let mut out = Self::default();
135        if version >= 0 { out.name = if flex { get_compact_string_owned(buf)? } else { get_string_owned(buf)? }; }
136        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(ReassignablePartitionResponse::decode(buf, version)?); } v }; }
137        if flex {
138            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| {
139                Ok(false)
140            })?;
141        }
142        Ok(out)
143    }
144}
145
146#[derive(Debug, Clone, PartialEq, Eq, Default)]
147pub struct ReassignablePartitionResponse {
148    pub partition_index: i32,
149    pub error_code: i16,
150    pub error_message: Option<String>,
151    pub unknown_tagged_fields: UnknownTaggedFields,
152}
153
154impl Encode for ReassignablePartitionResponse {
155    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
156        let flex = version >= 0;
157        if version >= 0 { put_i32(buf, self.partition_index) }
158        if version >= 0 { put_i16(buf, self.error_code) }
159        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()) } }
160        if flex {
161            let tagged = WriteTaggedFields::new();
162            tagged.write(buf, &self.unknown_tagged_fields);
163        }
164        Ok(())
165    }
166    fn encoded_len(&self, version: i16) -> usize {
167        let flex = version >= 0;
168        let mut n: usize = 0;
169        if version >= 0 { n += 4; }
170        if version >= 0 { n += 2; }
171        if version >= 0 { n += if flex { compact_nullable_string_len(self.error_message.as_deref()) } else { nullable_string_len(self.error_message.as_deref()) }; }
172        if flex {
173            let known_pairs: Vec<(u32, usize)> = Vec::new();
174            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
175        }
176        n
177    }
178}
179
180impl<'de> Decode<'de> for ReassignablePartitionResponse {
181    fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
182        let flex = version >= 0;
183        let mut out = Self::default();
184        if version >= 0 { out.partition_index = get_i32(buf)?; }
185        if version >= 0 { out.error_code = get_i16(buf)?; }
186        if version >= 0 { out.error_message = if flex { get_compact_nullable_string_owned(buf)? } else { get_nullable_string_owned(buf)? }; }
187        if flex {
188            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| {
189                Ok(false)
190            })?;
191        }
192        Ok(out)
193    }
194}
195
196/// Default JSON payload matching `Self::default()` for JVM oracle differential testing.
197/// Only includes fields valid for the given version.
198#[must_use]
199#[allow(unused_comparisons)]
200pub fn default_json(version: i16) -> ::serde_json::Value {
201    let mut obj = ::serde_json::Map::new();
202    obj.insert("throttleTimeMs".to_string(), ::serde_json::json!(0));
203    if version >= 1 {
204        obj.insert("allowReplicationFactorChange".to_string(), ::serde_json::Value::Bool(true));
205    }
206    obj.insert("errorCode".to_string(), ::serde_json::json!(0));
207    obj.insert("errorMessage".to_string(), ::serde_json::Value::Null);
208    obj.insert("responses".to_string(), ::serde_json::Value::Array(vec![]));
209    ::serde_json::Value::Object(obj)
210}