Skip to main content

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

1// AUTO-GENERATED by crabka-protocol-codegen against a9ce3221537b8653448750697915607dc7936cf3. Do not edit.
2
3use crate::primitives::fixed::{get_i32, put_i32};
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, string_len,
8};
9use crate::tagged_fields::{WriteTaggedFields, read_tagged_fields, tagged_fields_len};
10use crate::{Decode, Encode, ProtocolError, UnknownTaggedFields};
11use bytes::{Buf, BufMut};
12pub const API_KEY: i16 = 76;
13pub const MIN_VERSION: i16 = 1;
14pub const MAX_VERSION: i16 = 1;
15pub const FLEXIBLE_MIN: i16 = 0;
16#[inline]
17fn is_flexible(version: i16) -> bool {
18    version >= FLEXIBLE_MIN
19}
20#[derive(Debug, Clone, PartialEq, Eq, Default)]
21pub struct ShareGroupHeartbeatRequest {
22    pub group_id: String,
23    pub member_id: String,
24    pub member_epoch: i32,
25    pub rack_id: Option<String>,
26    pub subscribed_topic_names: Option<Vec<String>>,
27    pub unknown_tagged_fields: UnknownTaggedFields,
28}
29impl Encode for ShareGroupHeartbeatRequest {
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 {
33                api_key: API_KEY,
34                version,
35            });
36        }
37        let flex = is_flexible(version);
38        if version >= 0 {
39            if flex {
40                put_compact_string(buf, &self.group_id);
41            } else {
42                put_string(buf, &self.group_id);
43            }
44        }
45        if version >= 0 {
46            if flex {
47                put_compact_string(buf, &self.member_id);
48            } else {
49                put_string(buf, &self.member_id);
50            }
51        }
52        if version >= 0 {
53            put_i32(buf, self.member_epoch);
54        }
55        if version >= 0 {
56            if flex {
57                put_compact_nullable_string(buf, self.rack_id.as_deref());
58            } else {
59                put_nullable_string(buf, self.rack_id.as_deref());
60            }
61        }
62        if version >= 0 {
63            {
64                let len = (self.subscribed_topic_names).as_ref().map(Vec::len);
65                crate::primitives::array::put_nullable_array_len(buf, len, flex);
66                if let Some(v) = &self.subscribed_topic_names {
67                    for it in v {
68                        if flex {
69                            put_compact_string(buf, it);
70                        } else {
71                            put_string(buf, it);
72                        }
73                    }
74                }
75            }
76        }
77        if flex {
78            let tagged = WriteTaggedFields::new();
79            tagged.write(buf, &self.unknown_tagged_fields);
80        }
81        Ok(())
82    }
83    fn encoded_len(&self, version: i16) -> usize {
84        let flex = is_flexible(version);
85        let mut n: usize = 0;
86        if version >= 0 {
87            n += if flex {
88                compact_string_len(&self.group_id)
89            } else {
90                string_len(&self.group_id)
91            };
92        }
93        if version >= 0 {
94            n += if flex {
95                compact_string_len(&self.member_id)
96            } else {
97                string_len(&self.member_id)
98            };
99        }
100        if version >= 0 {
101            n += 4;
102        }
103        if version >= 0 {
104            n += if flex {
105                compact_nullable_string_len(self.rack_id.as_deref())
106            } else {
107                nullable_string_len(self.rack_id.as_deref())
108            };
109        }
110        if version >= 0 {
111            n += {
112                let opt: Option<&Vec<_>> = (self.subscribed_topic_names).as_ref();
113                let prefix = crate::primitives::array::nullable_array_len_prefix_len(
114                    opt.map(std::vec::Vec::len),
115                    flex,
116                );
117                let body: usize = opt.map_or(0, |v| {
118                    v.iter()
119                        .map(|it| {
120                            if flex {
121                                compact_string_len(it)
122                            } else {
123                                string_len(it)
124                            }
125                        })
126                        .sum()
127                });
128                prefix + body
129            };
130        }
131        if flex {
132            let known_pairs: Vec<(u32, usize)> = Vec::new();
133            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
134        }
135        n
136    }
137}
138impl Decode<'_> for ShareGroupHeartbeatRequest {
139    fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
140        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
141            return Err(ProtocolError::UnsupportedVersion {
142                api_key: API_KEY,
143                version,
144            });
145        }
146        let flex = is_flexible(version);
147        let mut out = Self::default();
148        if version >= 0 {
149            out.group_id = if flex {
150                get_compact_string_owned(buf)?
151            } else {
152                get_string_owned(buf)?
153            };
154        }
155        if version >= 0 {
156            out.member_id = if flex {
157                get_compact_string_owned(buf)?
158            } else {
159                get_string_owned(buf)?
160            };
161        }
162        if version >= 0 {
163            out.member_epoch = get_i32(buf)?;
164        }
165        if version >= 0 {
166            out.rack_id = if flex {
167                get_compact_nullable_string_owned(buf)?
168            } else {
169                get_nullable_string_owned(buf)?
170            };
171        }
172        if version >= 0 {
173            out.subscribed_topic_names = {
174                let opt = crate::primitives::array::get_nullable_array_len(buf, flex)?;
175                match opt {
176                    None => None,
177                    Some(n) => {
178                        let mut v = Vec::with_capacity(n);
179                        for _ in 0..n {
180                            v.push(if flex {
181                                get_compact_string_owned(buf)?
182                            } else {
183                                get_string_owned(buf)?
184                            });
185                        }
186                        Some(v)
187                    }
188                }
189            };
190        }
191        if flex {
192            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
193        }
194        Ok(out)
195    }
196}
197#[cfg(test)]
198impl ShareGroupHeartbeatRequest {
199    #[must_use]
200    pub fn populated(version: i16) -> Self {
201        let mut m = Self::default();
202        if version >= 0 {
203            m.group_id = "x".to_string();
204        }
205        if version >= 0 {
206            m.member_id = "x".to_string();
207        }
208        if version >= 0 {
209            m.member_epoch = 1i32;
210        }
211        if version >= 0 {
212            m.rack_id = Some("x".to_string());
213        }
214        if version >= 0 {
215            m.subscribed_topic_names = Some(vec!["x".to_string()]);
216        }
217        m
218    }
219}
220/// Default JSON payload matching `Self::default()` for JVM oracle differential testing.
221/// Only includes fields valid for the given version.
222#[must_use]
223#[allow(unused_comparisons)]
224pub fn default_json(version: i16) -> ::serde_json::Value {
225    let mut obj = ::serde_json::Map::new();
226    obj.insert(
227        "groupId".to_string(),
228        ::serde_json::Value::String(String::new()),
229    );
230    obj.insert(
231        "memberId".to_string(),
232        ::serde_json::Value::String(String::new()),
233    );
234    obj.insert("memberEpoch".to_string(), ::serde_json::json!(0));
235    obj.insert("rackId".to_string(), ::serde_json::Value::Null);
236    obj.insert(
237        "subscribedTopicNames".to_string(),
238        ::serde_json::Value::Null,
239    );
240    ::serde_json::Value::Object(obj)
241}
242impl crate::ProtocolRequest for ShareGroupHeartbeatRequest {
243    const API_KEY: i16 = API_KEY;
244    const MIN_VERSION: i16 = MIN_VERSION;
245    const MAX_VERSION: i16 = MAX_VERSION;
246    const FLEXIBLE_MIN: i16 = FLEXIBLE_MIN;
247    type Response = super::share_group_heartbeat_response::ShareGroupHeartbeatResponse;
248}