Skip to main content

crabka_protocol/opt/rustwide/workdir/generated/
ListPartitionReassignmentsRequest.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::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 = 46;
14pub const MIN_VERSION: i16 = 0;
15pub const MAX_VERSION: i16 = 0;
16pub const FLEXIBLE_MIN: i16 = 0;
17
18#[inline]
19fn is_flexible(version: i16) -> bool { version >= FLEXIBLE_MIN }
20
21#[derive(Debug, Clone, PartialEq, Eq)]
22pub struct ListPartitionReassignmentsRequest {
23    pub timeout_ms: i32,
24    pub topics: Option<Vec<ListPartitionReassignmentsTopics>>,
25    pub unknown_tagged_fields: UnknownTaggedFields,
26}
27
28impl Default for ListPartitionReassignmentsRequest {
29    fn default() -> Self {
30        Self {
31            timeout_ms: 60_000i32,
32            topics: None,
33            unknown_tagged_fields: Default::default(),
34        }
35    }
36}
37
38impl Encode for ListPartitionReassignmentsRequest {
39    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
40        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
41            return Err(ProtocolError::UnsupportedVersion { api_key: API_KEY, version });
42        }
43        let flex = is_flexible(version);
44        if version >= 0 { put_i32(buf, self.timeout_ms) }
45        if version >= 0 { { let len = (self.topics).as_ref().map(Vec::len); crate::primitives::array::put_nullable_array_len(buf, len, flex); if let Some(v) = &self.topics { for it in v { it.encode(buf, version)?; } } } }
46        if flex {
47            let tagged = WriteTaggedFields::new();
48            tagged.write(buf, &self.unknown_tagged_fields);
49        }
50        Ok(())
51    }
52    fn encoded_len(&self, version: i16) -> usize {
53        let flex = is_flexible(version);
54        let mut n: usize = 0;
55        if version >= 0 { n += 4; }
56        if version >= 0 { n += { let opt: Option<&Vec<_>> = (self.topics).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 }; }
57        if flex {
58            let known_pairs: Vec<(u32, usize)> = Vec::new();
59            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
60        }
61        n
62    }
63}
64
65impl<'de> Decode<'de> for ListPartitionReassignmentsRequest {
66    fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
67        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
68            return Err(ProtocolError::UnsupportedVersion { api_key: API_KEY, version });
69        }
70        let flex = is_flexible(version);
71        let mut out = Self::default();
72        if version >= 0 { out.timeout_ms = get_i32(buf)?; }
73        if version >= 0 { out.topics = { 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(ListPartitionReassignmentsTopics::decode(buf, version)?); } Some(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 ListPartitionReassignmentsTopics {
85    pub name: String,
86    pub partition_indexes: Vec<i32>,
87    pub unknown_tagged_fields: UnknownTaggedFields,
88}
89
90impl Encode for ListPartitionReassignmentsTopics {
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.partition_indexes).len(), flex); for it in &self.partition_indexes { put_i32(buf, *it); } } }
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.partition_indexes).len(), flex); let body: usize = (self.partition_indexes).iter().map(|_| 4).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 ListPartitionReassignmentsTopics {
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.partition_indexes = { 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 }; }
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/// Default JSON payload matching `Self::default()` for JVM oracle differential testing.
130/// Only includes fields valid for the given version.
131#[must_use]
132#[allow(unused_comparisons)]
133pub fn default_json(version: i16) -> ::serde_json::Value {
134    let mut obj = ::serde_json::Map::new();
135    obj.insert("timeoutMs".to_string(), ::serde_json::json!(60000));
136    obj.insert("topics".to_string(), ::serde_json::Value::Null);
137    ::serde_json::Value::Object(obj)
138}
139
140impl crate::ProtocolRequest for ListPartitionReassignmentsRequest {
141    const API_KEY: i16 = API_KEY;
142    const MIN_VERSION: i16 = MIN_VERSION;
143    const MAX_VERSION: i16 = MAX_VERSION;
144    const FLEXIBLE_MIN: i16 = FLEXIBLE_MIN;
145    type Response = super::list_partition_reassignments_response::ListPartitionReassignmentsResponse;
146}