crabka_protocol/opt/rustwide/workdir/generated/
OffsetDeleteResponse.owned.rs1use bytes::{Buf, BufMut};
4
5use crate::primitives::fixed::{get_i16, get_i32, put_i16, 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 OffsetDeleteResponse {
22 pub error_code: i16,
23 pub throttle_time_ms: i32,
24 pub topics: Vec<OffsetDeleteResponseTopic>,
25 pub unknown_tagged_fields: UnknownTaggedFields,
26}
27
28impl Encode for OffsetDeleteResponse {
29 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
30 if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
31 return Err(ProtocolError::UnsupportedVersion { api_key: API_KEY, version });
32 }
33 let flex = is_flexible(version);
34 if version >= 0 { put_i16(buf, self.error_code) }
35 if version >= 0 { put_i32(buf, self.throttle_time_ms) }
36 if version >= 0 { { crate::primitives::array::put_array_len(buf, (self.topics).len(), flex); for it in &self.topics { it.encode(buf, version)?; } } }
37 Ok(())
38 }
39 fn encoded_len(&self, version: i16) -> usize {
40 let flex = is_flexible(version);
41 let mut n: usize = 0;
42 if version >= 0 { n += 2; }
43 if version >= 0 { n += 4; }
44 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 }; }
45 n
46 }
47}
48
49impl<'de> Decode<'de> for OffsetDeleteResponse {
50 fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
51 if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
52 return Err(ProtocolError::UnsupportedVersion { api_key: API_KEY, version });
53 }
54 let flex = is_flexible(version);
55 let mut out = Self::default();
56 if version >= 0 { out.error_code = get_i16(buf)?; }
57 if version >= 0 { out.throttle_time_ms = get_i32(buf)?; }
58 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(OffsetDeleteResponseTopic::decode(buf, version)?); } v }; }
59 Ok(out)
60 }
61}
62
63#[derive(Debug, Clone, PartialEq, Eq, Default)]
64pub struct OffsetDeleteResponseTopic {
65 pub name: String,
66 pub partitions: Vec<OffsetDeleteResponsePartition>,
67 pub unknown_tagged_fields: UnknownTaggedFields,
68}
69
70impl Encode for OffsetDeleteResponseTopic {
71 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
72 let flex = version >= 32767;
73 if version >= 0 { if flex { put_compact_string(buf, &self.name) } else { put_string(buf, &self.name) } }
74 if version >= 0 { { crate::primitives::array::put_array_len(buf, (self.partitions).len(), flex); for it in &self.partitions { it.encode(buf, version)?; } } }
75 Ok(())
76 }
77 fn encoded_len(&self, version: i16) -> usize {
78 let flex = version >= 32767;
79 let mut n: usize = 0;
80 if version >= 0 { n += if flex { compact_string_len(&self.name) } else { string_len(&self.name) }; }
81 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 }; }
82 n
83 }
84}
85
86impl<'de> Decode<'de> for OffsetDeleteResponseTopic {
87 fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
88 let flex = version >= 32767;
89 let mut out = Self::default();
90 if version >= 0 { out.name = if flex { get_compact_string_owned(buf)? } else { get_string_owned(buf)? }; }
91 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(OffsetDeleteResponsePartition::decode(buf, version)?); } v }; }
92 Ok(out)
93 }
94}
95
96#[derive(Debug, Clone, PartialEq, Eq, Default)]
97pub struct OffsetDeleteResponsePartition {
98 pub partition_index: i32,
99 pub error_code: i16,
100 pub unknown_tagged_fields: UnknownTaggedFields,
101}
102
103impl Encode for OffsetDeleteResponsePartition {
104 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
105 let flex = version >= 32767;
106 if version >= 0 { put_i32(buf, self.partition_index) }
107 if version >= 0 { put_i16(buf, self.error_code) }
108 Ok(())
109 }
110 fn encoded_len(&self, version: i16) -> usize {
111 let flex = version >= 32767;
112 let mut n: usize = 0;
113 if version >= 0 { n += 4; }
114 if version >= 0 { n += 2; }
115 n
116 }
117}
118
119impl<'de> Decode<'de> for OffsetDeleteResponsePartition {
120 fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
121 let flex = version >= 32767;
122 let mut out = Self::default();
123 if version >= 0 { out.partition_index = get_i32(buf)?; }
124 if version >= 0 { out.error_code = get_i16(buf)?; }
125 Ok(out)
126 }
127}
128
129#[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("errorCode".to_string(), ::serde_json::json!(0));
136 obj.insert("throttleTimeMs".to_string(), ::serde_json::json!(0));
137 obj.insert("topics".to_string(), ::serde_json::Value::Array(vec![]));
138 ::serde_json::Value::Object(obj)
139}