Skip to main content

krabka_protocol/opt/rustwide/workdir/generated/
HeartbeatRequest.owned.rs

1// AUTO-GENERATED by krabka-protocol-codegen against a9ce3221537b8653448750697915607dc7936cf3. Do not edit.
2
3use bytes::{Buf, BufMut};
4
5use crate::{
6    Decode, Encode, ProtocolError, UnknownTaggedFields,
7    primitives::{
8        fixed::{get_i32, put_i32},
9        string_bytes::{
10            compact_nullable_string_len, compact_string_len, get_compact_nullable_string_owned,
11            get_compact_string_owned, get_nullable_string_owned, get_string_owned,
12            nullable_string_len, put_compact_nullable_string, put_compact_string,
13            put_nullable_string, put_string, string_len,
14        },
15    },
16    tagged_fields::{WriteTaggedFields, read_tagged_fields, tagged_fields_len},
17};
18pub const API_KEY: i16 = 12;
19pub const MIN_VERSION: i16 = 0;
20pub const MAX_VERSION: i16 = 4;
21pub const LATEST_STABLE_VERSION: i16 = 4;
22pub const FLEXIBLE_MIN: i16 = 4;
23#[inline]
24#[must_use]
25pub fn is_flexible(version: i16) -> bool {
26    version >= FLEXIBLE_MIN
27}
28#[derive(Debug, Clone, PartialEq, Eq, Default)]
29pub struct HeartbeatRequest {
30    pub group_id: String,
31    pub generation_id: i32,
32    pub member_id: String,
33    pub group_instance_id: Option<String>,
34    pub unknown_tagged_fields: UnknownTaggedFields,
35}
36impl Encode for HeartbeatRequest {
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 {
40                api_key: API_KEY,
41                version,
42            });
43        }
44        let flex = is_flexible(version);
45        if version >= 0 {
46            if flex {
47                let () = put_compact_string(buf, &self.group_id);
48            } else {
49                let () = put_string(buf, &self.group_id);
50            }
51        }
52        if version >= 0 {
53            put_i32(buf, self.generation_id);
54        }
55        if version >= 0 {
56            if flex {
57                let () = put_compact_string(buf, &self.member_id);
58            } else {
59                let () = put_string(buf, &self.member_id);
60            }
61        }
62        if version >= 3 {
63            if flex {
64                let () = put_compact_nullable_string(buf, self.group_instance_id.as_deref());
65            } else {
66                let () = put_nullable_string(buf, self.group_instance_id.as_deref());
67            }
68        }
69        if flex {
70            let tagged = WriteTaggedFields::new();
71            tagged.write(buf, &self.unknown_tagged_fields);
72        }
73        Ok(())
74    }
75    fn encoded_len(&self, version: i16) -> usize {
76        let flex = is_flexible(version);
77        let mut n: usize = 0;
78        if version >= 0 {
79            n += if flex {
80                compact_string_len(&self.group_id)
81            } else {
82                string_len(&self.group_id)
83            };
84        }
85        if version >= 0 {
86            n += 4;
87        }
88        if version >= 0 {
89            n += if flex {
90                compact_string_len(&self.member_id)
91            } else {
92                string_len(&self.member_id)
93            };
94        }
95        if version >= 3 {
96            n += if flex {
97                compact_nullable_string_len(self.group_instance_id.as_deref())
98            } else {
99                nullable_string_len(self.group_instance_id.as_deref())
100            };
101        }
102        if flex {
103            let known_pairs: Vec<(u32, usize)> = Vec::new();
104            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
105        }
106        n
107    }
108}
109impl Decode<'_> for HeartbeatRequest {
110    fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
111        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
112            return Err(ProtocolError::UnsupportedVersion {
113                api_key: API_KEY,
114                version,
115            });
116        }
117        let flex = is_flexible(version);
118        let mut out = Self::default();
119        if version >= 0 {
120            out.group_id = if flex {
121                get_compact_string_owned(buf)?
122            } else {
123                get_string_owned(buf)?
124            };
125        }
126        if version >= 0 {
127            out.generation_id = get_i32(buf)?;
128        }
129        if version >= 0 {
130            out.member_id = if flex {
131                get_compact_string_owned(buf)?
132            } else {
133                get_string_owned(buf)?
134            };
135        }
136        if version >= 3 {
137            out.group_instance_id = if flex {
138                get_compact_nullable_string_owned(buf)?
139            } else {
140                get_nullable_string_owned(buf)?
141            };
142        }
143        if flex {
144            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
145        }
146        Ok(out)
147    }
148}
149#[cfg(test)]
150impl HeartbeatRequest {
151    #[must_use]
152    pub fn populated(version: i16) -> Self {
153        let mut m = Self::default();
154        if version >= 0 {
155            m.group_id = "x".to_string();
156        }
157        if version >= 0 {
158            m.generation_id = 1i32;
159        }
160        if version >= 0 {
161            m.member_id = "x".to_string();
162        }
163        if version >= 3 {
164            m.group_instance_id = Some("x".to_string());
165        }
166        m
167    }
168}
169/// Default JSON payload matching `Self::default()` for JVM oracle differential testing.
170/// Only includes fields valid for the given version.
171#[must_use]
172#[allow(unused_comparisons)]
173pub fn default_json(version: i16) -> ::serde_json::Value {
174    let mut obj = ::serde_json::Map::new();
175    obj.insert(
176        "groupId".to_string(),
177        ::serde_json::Value::String(String::new()),
178    );
179    obj.insert("generationId".to_string(), ::serde_json::json!(0));
180    obj.insert(
181        "memberId".to_string(),
182        ::serde_json::Value::String(String::new()),
183    );
184    if version >= 3 {
185        obj.insert("groupInstanceId".to_string(), ::serde_json::Value::Null);
186    }
187    ::serde_json::Value::Object(obj)
188}
189impl crate::ProtocolRequest for HeartbeatRequest {
190    const API_KEY: i16 = API_KEY;
191    const MIN_VERSION: i16 = MIN_VERSION;
192    const MAX_VERSION: i16 = MAX_VERSION;
193    const LATEST_STABLE_VERSION: i16 = LATEST_STABLE_VERSION;
194    const FLEXIBLE_MIN: i16 = FLEXIBLE_MIN;
195    type Response = super::heartbeat_response::HeartbeatResponse;
196}