Skip to main content

crabka_protocol/opt/rustwide/workdir/generated/
CreatePartitionsRequest.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_i32, put_bool, put_i32};
6use crate::primitives::string_bytes::{
7    compact_string_len, get_compact_string_owned, get_string_owned,
8    put_compact_string, put_string, string_len,
9};
10use crate::tagged_fields::{read_tagged_fields, tagged_fields_len, WriteTaggedFields};
11use crate::{Decode, Encode, ProtocolError, UnknownTaggedFields};
12
13pub const API_KEY: i16 = 37;
14pub const MIN_VERSION: i16 = 0;
15pub const MAX_VERSION: i16 = 3;
16pub const FLEXIBLE_MIN: i16 = 2;
17
18#[inline]
19fn is_flexible(version: i16) -> bool { version >= FLEXIBLE_MIN }
20
21#[derive(Debug, Clone, PartialEq, Eq, Default)]
22pub struct CreatePartitionsRequest {
23    pub topics: Vec<CreatePartitionsTopic>,
24    pub timeout_ms: i32,
25    pub validate_only: bool,
26    pub unknown_tagged_fields: UnknownTaggedFields,
27}
28
29impl Encode for CreatePartitionsRequest {
30    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
31        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
32            return Err(ProtocolError::UnsupportedVersion { api_key: API_KEY, version });
33        }
34        let flex = is_flexible(version);
35        if version >= 0 { { crate::primitives::array::put_array_len(buf, (self.topics).len(), flex); for it in &self.topics { it.encode(buf, version)?; } } }
36        if version >= 0 { put_i32(buf, self.timeout_ms) }
37        if version >= 0 { put_bool(buf, self.validate_only) }
38        if flex {
39            let tagged = WriteTaggedFields::new();
40            tagged.write(buf, &self.unknown_tagged_fields);
41        }
42        Ok(())
43    }
44    fn encoded_len(&self, version: i16) -> usize {
45        let flex = is_flexible(version);
46        let mut n: usize = 0;
47        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 }; }
48        if version >= 0 { n += 4; }
49        if version >= 0 { n += 1; }
50        if flex {
51            let known_pairs: Vec<(u32, usize)> = Vec::new();
52            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
53        }
54        n
55    }
56}
57
58impl<'de> Decode<'de> for CreatePartitionsRequest {
59    fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
60        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
61            return Err(ProtocolError::UnsupportedVersion { api_key: API_KEY, version });
62        }
63        let flex = is_flexible(version);
64        let mut out = Self::default();
65        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(CreatePartitionsTopic::decode(buf, version)?); } v }; }
66        if version >= 0 { out.timeout_ms = get_i32(buf)?; }
67        if version >= 0 { out.validate_only = get_bool(buf)?; }
68        if flex {
69            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| {
70                Ok(false)
71            })?;
72        }
73        Ok(out)
74    }
75}
76
77#[derive(Debug, Clone, PartialEq, Eq, Default)]
78pub struct CreatePartitionsTopic {
79    pub name: String,
80    pub count: i32,
81    pub assignments: Option<Vec<CreatePartitionsAssignment>>,
82    pub unknown_tagged_fields: UnknownTaggedFields,
83}
84
85impl Encode for CreatePartitionsTopic {
86    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
87        let flex = version >= 2;
88        if version >= 0 { if flex { put_compact_string(buf, &self.name) } else { put_string(buf, &self.name) } }
89        if version >= 0 { put_i32(buf, self.count) }
90        if version >= 0 { { let len = (self.assignments).as_ref().map(Vec::len); crate::primitives::array::put_nullable_array_len(buf, len, flex); if let Some(v) = &self.assignments { for it in v { it.encode(buf, version)?; } } } }
91        if flex {
92            let tagged = WriteTaggedFields::new();
93            tagged.write(buf, &self.unknown_tagged_fields);
94        }
95        Ok(())
96    }
97    fn encoded_len(&self, version: i16) -> usize {
98        let flex = version >= 2;
99        let mut n: usize = 0;
100        if version >= 0 { n += if flex { compact_string_len(&self.name) } else { string_len(&self.name) }; }
101        if version >= 0 { n += 4; }
102        if version >= 0 { n += { let opt: Option<&Vec<_>> = (self.assignments).as_ref(); let prefix = crate::primitives::array::nullable_array_len_prefix_len(opt.map(|v| v.len()), flex); let body: usize = opt.map_or(0, |v| v.iter().map(|it| it.encoded_len(version)).sum()); prefix + body }; }
103        if flex {
104            let known_pairs: Vec<(u32, usize)> = Vec::new();
105            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
106        }
107        n
108    }
109}
110
111impl<'de> Decode<'de> for CreatePartitionsTopic {
112    fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
113        let flex = version >= 2;
114        let mut out = Self::default();
115        if version >= 0 { out.name = if flex { get_compact_string_owned(buf)? } else { get_string_owned(buf)? }; }
116        if version >= 0 { out.count = get_i32(buf)?; }
117        if version >= 0 { out.assignments = { let opt = crate::primitives::array::get_nullable_array_len(buf, flex)?; match opt { None => None, Some(n) => { let mut v = Vec::with_capacity(n); for _ in 0..n { v.push(CreatePartitionsAssignment::decode(buf, version)?); } Some(v) } } }; }
118        if flex {
119            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| {
120                Ok(false)
121            })?;
122        }
123        Ok(out)
124    }
125}
126
127#[derive(Debug, Clone, PartialEq, Eq, Default)]
128pub struct CreatePartitionsAssignment {
129    pub broker_ids: Vec<i32>,
130    pub unknown_tagged_fields: UnknownTaggedFields,
131}
132
133impl Encode for CreatePartitionsAssignment {
134    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
135        let flex = version >= 2;
136        if version >= 0 { { crate::primitives::array::put_array_len(buf, (self.broker_ids).len(), flex); for it in &self.broker_ids { put_i32(buf, *it); } } }
137        if flex {
138            let tagged = WriteTaggedFields::new();
139            tagged.write(buf, &self.unknown_tagged_fields);
140        }
141        Ok(())
142    }
143    fn encoded_len(&self, version: i16) -> usize {
144        let flex = version >= 2;
145        let mut n: usize = 0;
146        if version >= 0 { n += { let prefix = crate::primitives::array::array_len_prefix_len((self.broker_ids).len(), flex); let body: usize = (self.broker_ids).iter().map(|_| 4).sum(); prefix + body }; }
147        if flex {
148            let known_pairs: Vec<(u32, usize)> = Vec::new();
149            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
150        }
151        n
152    }
153}
154
155impl<'de> Decode<'de> for CreatePartitionsAssignment {
156    fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
157        let flex = version >= 2;
158        let mut out = Self::default();
159        if version >= 0 { out.broker_ids = { 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 }; }
160        if flex {
161            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| {
162                Ok(false)
163            })?;
164        }
165        Ok(out)
166    }
167}
168
169/// Default JSON payload matching `Self::default()` for JVM oracle differential testing.
170/// Only includes fields valid for the given version.
171#[must_use]
172#[allow(unused_comparisons)]
173pub fn default_json(version: i16) -> ::serde_json::Value {
174    let mut obj = ::serde_json::Map::new();
175    obj.insert("topics".to_string(), ::serde_json::Value::Array(vec![]));
176    obj.insert("timeoutMs".to_string(), ::serde_json::json!(0));
177    obj.insert("validateOnly".to_string(), ::serde_json::Value::Bool(false));
178    ::serde_json::Value::Object(obj)
179}
180
181impl crate::ProtocolRequest for CreatePartitionsRequest {
182    const API_KEY: i16 = API_KEY;
183    const MIN_VERSION: i16 = MIN_VERSION;
184    const MAX_VERSION: i16 = MAX_VERSION;
185    const FLEXIBLE_MIN: i16 = FLEXIBLE_MIN;
186    type Response = super::create_partitions_response::CreatePartitionsResponse;
187}