Skip to main content

crabka_protocol/opt/rustwide/workdir/generated/
SyncGroupRequest.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_nullable_string_len, compact_string_len, get_compact_nullable_string_owned,
8    get_compact_string_owned, get_nullable_string_owned, get_string_owned, nullable_string_len,
9    put_compact_nullable_string, put_compact_string, put_nullable_string, put_string,
10    string_len,
11};
12use crate::primitives::string_bytes::{bytes_len, compact_bytes_len, get_bytes_owned, get_compact_bytes_owned, put_bytes, put_compact_bytes};
13use crate::tagged_fields::{read_tagged_fields, tagged_fields_len, WriteTaggedFields};
14use crate::{Decode, Encode, ProtocolError, UnknownTaggedFields};
15
16pub const API_KEY: i16 = 14;
17pub const MIN_VERSION: i16 = 0;
18pub const MAX_VERSION: i16 = 5;
19pub const FLEXIBLE_MIN: i16 = 4;
20
21#[inline]
22fn is_flexible(version: i16) -> bool { version >= FLEXIBLE_MIN }
23
24#[derive(Debug, Clone, PartialEq, Eq, Default)]
25pub struct SyncGroupRequest {
26    pub group_id: String,
27    pub generation_id: i32,
28    pub member_id: String,
29    pub group_instance_id: Option<String>,
30    pub protocol_type: Option<String>,
31    pub protocol_name: Option<String>,
32    pub assignments: Vec<SyncGroupRequestAssignment>,
33    pub unknown_tagged_fields: UnknownTaggedFields,
34}
35
36impl Encode for SyncGroupRequest {
37    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
38        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
39            return Err(ProtocolError::UnsupportedVersion { api_key: API_KEY, version });
40        }
41        let flex = is_flexible(version);
42        if version >= 0 { if flex { put_compact_string(buf, &self.group_id) } else { put_string(buf, &self.group_id) } }
43        if version >= 0 { put_i32(buf, self.generation_id) }
44        if version >= 0 { if flex { put_compact_string(buf, &self.member_id) } else { put_string(buf, &self.member_id) } }
45        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()) } }
46        if version >= 5 { if flex { put_compact_nullable_string(buf, self.protocol_type.as_deref()) } else { put_nullable_string(buf, self.protocol_type.as_deref()) } }
47        if version >= 5 { if flex { put_compact_nullable_string(buf, self.protocol_name.as_deref()) } else { put_nullable_string(buf, self.protocol_name.as_deref()) } }
48        if version >= 0 { { crate::primitives::array::put_array_len(buf, (self.assignments).len(), flex); for it in &self.assignments { it.encode(buf, version)?; } } }
49        if flex {
50            let tagged = WriteTaggedFields::new();
51            tagged.write(buf, &self.unknown_tagged_fields);
52        }
53        Ok(())
54    }
55    fn encoded_len(&self, version: i16) -> usize {
56        let flex = is_flexible(version);
57        let mut n: usize = 0;
58        if version >= 0 { n += if flex { compact_string_len(&self.group_id) } else { string_len(&self.group_id) }; }
59        if version >= 0 { n += 4; }
60        if version >= 0 { n += if flex { compact_string_len(&self.member_id) } else { string_len(&self.member_id) }; }
61        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()) }; }
62        if version >= 5 { n += if flex { compact_nullable_string_len(self.protocol_type.as_deref()) } else { nullable_string_len(self.protocol_type.as_deref()) }; }
63        if version >= 5 { n += if flex { compact_nullable_string_len(self.protocol_name.as_deref()) } else { nullable_string_len(self.protocol_name.as_deref()) }; }
64        if version >= 0 { n += { let prefix = crate::primitives::array::array_len_prefix_len((self.assignments).len(), flex); let body: usize = (self.assignments).iter().map(|it| it.encoded_len(version)).sum(); prefix + body }; }
65        if flex {
66            let known_pairs: Vec<(u32, usize)> = Vec::new();
67            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
68        }
69        n
70    }
71}
72
73impl<'de> Decode<'de> for SyncGroupRequest {
74    fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
75        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
76            return Err(ProtocolError::UnsupportedVersion { api_key: API_KEY, version });
77        }
78        let flex = is_flexible(version);
79        let mut out = Self::default();
80        if version >= 0 { out.group_id = if flex { get_compact_string_owned(buf)? } else { get_string_owned(buf)? }; }
81        if version >= 0 { out.generation_id = get_i32(buf)?; }
82        if version >= 0 { out.member_id = if flex { get_compact_string_owned(buf)? } else { get_string_owned(buf)? }; }
83        if version >= 3 { out.group_instance_id = if flex { get_compact_nullable_string_owned(buf)? } else { get_nullable_string_owned(buf)? }; }
84        if version >= 5 { out.protocol_type = if flex { get_compact_nullable_string_owned(buf)? } else { get_nullable_string_owned(buf)? }; }
85        if version >= 5 { out.protocol_name = if flex { get_compact_nullable_string_owned(buf)? } else { get_nullable_string_owned(buf)? }; }
86        if version >= 0 { out.assignments = { let n = crate::primitives::array::get_array_len(buf, flex)?; let mut v = Vec::with_capacity(n); for _ in 0..n { v.push(SyncGroupRequestAssignment::decode(buf, version)?); } v }; }
87        if flex {
88            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| {
89                Ok(false)
90            })?;
91        }
92        Ok(out)
93    }
94}
95
96#[derive(Debug, Clone, PartialEq, Eq, Default)]
97pub struct SyncGroupRequestAssignment {
98    pub member_id: String,
99    pub assignment: ::bytes::Bytes,
100    pub unknown_tagged_fields: UnknownTaggedFields,
101}
102
103impl Encode for SyncGroupRequestAssignment {
104    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
105        let flex = version >= 4;
106        if version >= 0 { if flex { put_compact_string(buf, &self.member_id) } else { put_string(buf, &self.member_id) } }
107        if version >= 0 { if flex { put_compact_bytes(buf, &self.assignment) } else { put_bytes(buf, &self.assignment) } }
108        if flex {
109            let tagged = WriteTaggedFields::new();
110            tagged.write(buf, &self.unknown_tagged_fields);
111        }
112        Ok(())
113    }
114    fn encoded_len(&self, version: i16) -> usize {
115        let flex = version >= 4;
116        let mut n: usize = 0;
117        if version >= 0 { n += if flex { compact_string_len(&self.member_id) } else { string_len(&self.member_id) }; }
118        if version >= 0 { n += if flex { compact_bytes_len(&self.assignment) } else { bytes_len(&self.assignment) }; }
119        if flex {
120            let known_pairs: Vec<(u32, usize)> = Vec::new();
121            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
122        }
123        n
124    }
125}
126
127impl<'de> Decode<'de> for SyncGroupRequestAssignment {
128    fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
129        let flex = version >= 4;
130        let mut out = Self::default();
131        if version >= 0 { out.member_id = if flex { get_compact_string_owned(buf)? } else { get_string_owned(buf)? }; }
132        if version >= 0 { out.assignment = if flex { get_compact_bytes_owned(buf)? } else { get_bytes_owned(buf)? }; }
133        if flex {
134            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| {
135                Ok(false)
136            })?;
137        }
138        Ok(out)
139    }
140}
141
142/// Default JSON payload matching `Self::default()` for JVM oracle differential testing.
143/// Only includes fields valid for the given version.
144#[must_use]
145#[allow(unused_comparisons)]
146pub fn default_json(version: i16) -> ::serde_json::Value {
147    let mut obj = ::serde_json::Map::new();
148    obj.insert("groupId".to_string(), ::serde_json::Value::String(String::new()));
149    obj.insert("generationId".to_string(), ::serde_json::json!(0));
150    obj.insert("memberId".to_string(), ::serde_json::Value::String(String::new()));
151    if version >= 3 {
152        obj.insert("groupInstanceId".to_string(), ::serde_json::Value::Null);
153    }
154    if version >= 5 {
155        obj.insert("protocolType".to_string(), ::serde_json::Value::Null);
156    }
157    if version >= 5 {
158        obj.insert("protocolName".to_string(), ::serde_json::Value::Null);
159    }
160    obj.insert("assignments".to_string(), ::serde_json::Value::Array(vec![]));
161    ::serde_json::Value::Object(obj)
162}
163
164impl crate::ProtocolRequest for SyncGroupRequest {
165    const API_KEY: i16 = API_KEY;
166    const MIN_VERSION: i16 = MIN_VERSION;
167    const MAX_VERSION: i16 = MAX_VERSION;
168    const FLEXIBLE_MIN: i16 = FLEXIBLE_MIN;
169    type Response = super::sync_group_response::SyncGroupResponse;
170}