Skip to main content

crabka_protocol/opt/rustwide/workdir/generated/
LeaveGroupRequest.owned.rs

1// AUTO-GENERATED by crabka-protocol-codegen against a9ce3221537b8653448750697915607dc7936cf3. Do not edit.
2
3use bytes::{Buf, BufMut};
4use crate::primitives::string_bytes::{
5    compact_nullable_string_len, compact_string_len, get_compact_nullable_string_owned,
6    get_compact_string_owned, get_nullable_string_owned, get_string_owned, nullable_string_len,
7    put_compact_nullable_string, put_compact_string, put_nullable_string, put_string,
8    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 = 13;
14pub const MIN_VERSION: i16 = 0;
15pub const MAX_VERSION: i16 = 5;
16pub const FLEXIBLE_MIN: i16 = 4;
17
18#[inline]
19fn is_flexible(version: i16) -> bool { version >= FLEXIBLE_MIN }
20
21#[derive(Debug, Clone, PartialEq, Eq, Default)]
22pub struct LeaveGroupRequest {
23    pub group_id: String,
24    pub member_id: String,
25    pub members: Vec<MemberIdentity>,
26    pub unknown_tagged_fields: UnknownTaggedFields,
27}
28
29impl Encode for LeaveGroupRequest {
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 { if flex { put_compact_string(buf, &self.group_id) } else { put_string(buf, &self.group_id) } }
36        if version >= 0 && version <= 2 { if flex { put_compact_string(buf, &self.member_id) } else { put_string(buf, &self.member_id) } }
37        if version >= 3 { { crate::primitives::array::put_array_len(buf, (self.members).len(), flex); for it in &self.members { it.encode(buf, version)?; } } }
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 += if flex { compact_string_len(&self.group_id) } else { string_len(&self.group_id) }; }
48        if version >= 0 && version <= 2 { n += if flex { compact_string_len(&self.member_id) } else { string_len(&self.member_id) }; }
49        if version >= 3 { n += { let prefix = crate::primitives::array::array_len_prefix_len((self.members).len(), flex); let body: usize = (self.members).iter().map(|it| it.encoded_len(version)).sum(); prefix + body }; }
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 LeaveGroupRequest {
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.group_id = if flex { get_compact_string_owned(buf)? } else { get_string_owned(buf)? }; }
66        if version >= 0 && version <= 2 { out.member_id = if flex { get_compact_string_owned(buf)? } else { get_string_owned(buf)? }; }
67        if version >= 3 { out.members = { let n = crate::primitives::array::get_array_len(buf, flex)?; let mut v = Vec::with_capacity(n); for _ in 0..n { v.push(MemberIdentity::decode(buf, version)?); } v }; }
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 MemberIdentity {
79    pub member_id: String,
80    pub group_instance_id: Option<String>,
81    pub reason: Option<String>,
82    pub unknown_tagged_fields: UnknownTaggedFields,
83}
84
85impl Encode for MemberIdentity {
86    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
87        let flex = version >= 4;
88        if version >= 3 { if flex { put_compact_string(buf, &self.member_id) } else { put_string(buf, &self.member_id) } }
89        if version >= 3 { if flex { put_compact_nullable_string(buf, self.group_instance_id.as_deref()) } else { put_nullable_string(buf, self.group_instance_id.as_deref()) } }
90        if version >= 5 { if flex { put_compact_nullable_string(buf, self.reason.as_deref()) } else { put_nullable_string(buf, self.reason.as_deref()) } }
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 >= 4;
99        let mut n: usize = 0;
100        if version >= 3 { n += if flex { compact_string_len(&self.member_id) } else { string_len(&self.member_id) }; }
101        if version >= 3 { n += if flex { compact_nullable_string_len(self.group_instance_id.as_deref()) } else { nullable_string_len(self.group_instance_id.as_deref()) }; }
102        if version >= 5 { n += if flex { compact_nullable_string_len(self.reason.as_deref()) } else { nullable_string_len(self.reason.as_deref()) }; }
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 MemberIdentity {
112    fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
113        let flex = version >= 4;
114        let mut out = Self::default();
115        if version >= 3 { out.member_id = if flex { get_compact_string_owned(buf)? } else { get_string_owned(buf)? }; }
116        if version >= 3 { out.group_instance_id = if flex { get_compact_nullable_string_owned(buf)? } else { get_nullable_string_owned(buf)? }; }
117        if version >= 5 { out.reason = if flex { get_compact_nullable_string_owned(buf)? } else { get_nullable_string_owned(buf)? }; }
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/// Default JSON payload matching `Self::default()` for JVM oracle differential testing.
128/// Only includes fields valid for the given version.
129#[must_use]
130#[allow(unused_comparisons)]
131pub fn default_json(version: i16) -> ::serde_json::Value {
132    let mut obj = ::serde_json::Map::new();
133    obj.insert("groupId".to_string(), ::serde_json::Value::String(String::new()));
134    if version <= 2 {
135        obj.insert("memberId".to_string(), ::serde_json::Value::String(String::new()));
136    }
137    if version >= 3 {
138        obj.insert("members".to_string(), ::serde_json::Value::Array(vec![]));
139    }
140    ::serde_json::Value::Object(obj)
141}
142
143impl crate::ProtocolRequest for LeaveGroupRequest {
144    const API_KEY: i16 = API_KEY;
145    const MIN_VERSION: i16 = MIN_VERSION;
146    const MAX_VERSION: i16 = MAX_VERSION;
147    const FLEXIBLE_MIN: i16 = FLEXIBLE_MIN;
148    type Response = super::leave_group_response::LeaveGroupResponse;
149}