Skip to main content

crabka_protocol/opt/rustwide/workdir/generated/
OffsetDeleteRequest.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::{Decode, Encode, ProtocolError, UnknownTaggedFields};
11
12pub const API_KEY: i16 = 47;
13pub const MIN_VERSION: i16 = 0;
14pub const MAX_VERSION: i16 = 0;
15pub const FLEXIBLE_MIN: i16 = 32767;
16
17#[inline]
18fn is_flexible(version: i16) -> bool { version >= FLEXIBLE_MIN }
19
20#[derive(Debug, Clone, PartialEq, Eq, Default)]
21pub struct OffsetDeleteRequest {
22    pub group_id: String,
23    pub topics: Vec<OffsetDeleteRequestTopic>,
24    pub unknown_tagged_fields: UnknownTaggedFields,
25}
26
27impl Encode for OffsetDeleteRequest {
28    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
29        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
30            return Err(ProtocolError::UnsupportedVersion { api_key: API_KEY, version });
31        }
32        let flex = is_flexible(version);
33        if version >= 0 { if flex { put_compact_string(buf, &self.group_id) } else { put_string(buf, &self.group_id) } }
34        if version >= 0 { { crate::primitives::array::put_array_len(buf, (self.topics).len(), flex); for it in &self.topics { it.encode(buf, version)?; } } }
35        Ok(())
36    }
37    fn encoded_len(&self, version: i16) -> usize {
38        let flex = is_flexible(version);
39        let mut n: usize = 0;
40        if version >= 0 { n += if flex { compact_string_len(&self.group_id) } else { string_len(&self.group_id) }; }
41        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 }; }
42        n
43    }
44}
45
46impl<'de> Decode<'de> for OffsetDeleteRequest {
47    fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, 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        let mut out = Self::default();
53        if version >= 0 { out.group_id = if flex { get_compact_string_owned(buf)? } else { get_string_owned(buf)? }; }
54        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(OffsetDeleteRequestTopic::decode(buf, version)?); } v }; }
55        Ok(out)
56    }
57}
58
59#[derive(Debug, Clone, PartialEq, Eq, Default)]
60pub struct OffsetDeleteRequestTopic {
61    pub name: String,
62    pub partitions: Vec<OffsetDeleteRequestPartition>,
63    pub unknown_tagged_fields: UnknownTaggedFields,
64}
65
66impl Encode for OffsetDeleteRequestTopic {
67    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
68        let flex = version >= 32767;
69        if version >= 0 { if flex { put_compact_string(buf, &self.name) } else { put_string(buf, &self.name) } }
70        if version >= 0 { { crate::primitives::array::put_array_len(buf, (self.partitions).len(), flex); for it in &self.partitions { it.encode(buf, version)?; } } }
71        Ok(())
72    }
73    fn encoded_len(&self, version: i16) -> usize {
74        let flex = version >= 32767;
75        let mut n: usize = 0;
76        if version >= 0 { n += if flex { compact_string_len(&self.name) } else { string_len(&self.name) }; }
77        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 }; }
78        n
79    }
80}
81
82impl<'de> Decode<'de> for OffsetDeleteRequestTopic {
83    fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
84        let flex = version >= 32767;
85        let mut out = Self::default();
86        if version >= 0 { out.name = if flex { get_compact_string_owned(buf)? } else { get_string_owned(buf)? }; }
87        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(OffsetDeleteRequestPartition::decode(buf, version)?); } v }; }
88        Ok(out)
89    }
90}
91
92#[derive(Debug, Clone, PartialEq, Eq, Default)]
93pub struct OffsetDeleteRequestPartition {
94    pub partition_index: i32,
95    pub unknown_tagged_fields: UnknownTaggedFields,
96}
97
98impl Encode for OffsetDeleteRequestPartition {
99    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
100        let flex = version >= 32767;
101        if version >= 0 { put_i32(buf, self.partition_index) }
102        Ok(())
103    }
104    fn encoded_len(&self, version: i16) -> usize {
105        let flex = version >= 32767;
106        let mut n: usize = 0;
107        if version >= 0 { n += 4; }
108        n
109    }
110}
111
112impl<'de> Decode<'de> for OffsetDeleteRequestPartition {
113    fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
114        let flex = version >= 32767;
115        let mut out = Self::default();
116        if version >= 0 { out.partition_index = get_i32(buf)?; }
117        Ok(out)
118    }
119}
120
121/// Default JSON payload matching `Self::default()` for JVM oracle differential testing.
122/// Only includes fields valid for the given version.
123#[must_use]
124#[allow(unused_comparisons)]
125pub fn default_json(version: i16) -> ::serde_json::Value {
126    let mut obj = ::serde_json::Map::new();
127    obj.insert("groupId".to_string(), ::serde_json::Value::String(String::new()));
128    obj.insert("topics".to_string(), ::serde_json::Value::Array(vec![]));
129    ::serde_json::Value::Object(obj)
130}
131
132impl crate::ProtocolRequest for OffsetDeleteRequest {
133    const API_KEY: i16 = API_KEY;
134    const MIN_VERSION: i16 = MIN_VERSION;
135    const MAX_VERSION: i16 = MAX_VERSION;
136    const FLEXIBLE_MIN: i16 = FLEXIBLE_MIN;
137    type Response = super::offset_delete_response::OffsetDeleteResponse;
138}