Skip to main content

crabka_protocol/opt/rustwide/workdir/generated/
HeartbeatRequest.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::tagged_fields::{read_tagged_fields, tagged_fields_len, WriteTaggedFields};
13use crate::{Decode, Encode, ProtocolError, UnknownTaggedFields};
14
15pub const API_KEY: i16 = 12;
16pub const MIN_VERSION: i16 = 0;
17pub const MAX_VERSION: i16 = 4;
18pub const FLEXIBLE_MIN: i16 = 4;
19
20#[inline]
21fn is_flexible(version: i16) -> bool { version >= FLEXIBLE_MIN }
22
23#[derive(Debug, Clone, PartialEq, Eq, Default)]
24pub struct HeartbeatRequest {
25    pub group_id: String,
26    pub generation_id: i32,
27    pub member_id: String,
28    pub group_instance_id: Option<String>,
29    pub unknown_tagged_fields: UnknownTaggedFields,
30}
31
32impl Encode for HeartbeatRequest {
33    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
34        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
35            return Err(ProtocolError::UnsupportedVersion { api_key: API_KEY, version });
36        }
37        let flex = is_flexible(version);
38        if version >= 0 { if flex { put_compact_string(buf, &self.group_id) } else { put_string(buf, &self.group_id) } }
39        if version >= 0 { put_i32(buf, self.generation_id) }
40        if version >= 0 { if flex { put_compact_string(buf, &self.member_id) } else { put_string(buf, &self.member_id) } }
41        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()) } }
42        if flex {
43            let tagged = WriteTaggedFields::new();
44            tagged.write(buf, &self.unknown_tagged_fields);
45        }
46        Ok(())
47    }
48    fn encoded_len(&self, version: i16) -> usize {
49        let flex = is_flexible(version);
50        let mut n: usize = 0;
51        if version >= 0 { n += if flex { compact_string_len(&self.group_id) } else { string_len(&self.group_id) }; }
52        if version >= 0 { n += 4; }
53        if version >= 0 { n += if flex { compact_string_len(&self.member_id) } else { string_len(&self.member_id) }; }
54        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()) }; }
55        if flex {
56            let known_pairs: Vec<(u32, usize)> = Vec::new();
57            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
58        }
59        n
60    }
61}
62
63impl<'de> Decode<'de> for HeartbeatRequest {
64    fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
65        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
66            return Err(ProtocolError::UnsupportedVersion { api_key: API_KEY, version });
67        }
68        let flex = is_flexible(version);
69        let mut out = Self::default();
70        if version >= 0 { out.group_id = if flex { get_compact_string_owned(buf)? } else { get_string_owned(buf)? }; }
71        if version >= 0 { out.generation_id = get_i32(buf)?; }
72        if version >= 0 { out.member_id = if flex { get_compact_string_owned(buf)? } else { get_string_owned(buf)? }; }
73        if version >= 3 { out.group_instance_id = if flex { get_compact_nullable_string_owned(buf)? } else { get_nullable_string_owned(buf)? }; }
74        if flex {
75            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| {
76                Ok(false)
77            })?;
78        }
79        Ok(out)
80    }
81}
82
83/// Default JSON payload matching `Self::default()` for JVM oracle differential testing.
84/// Only includes fields valid for the given version.
85#[must_use]
86#[allow(unused_comparisons)]
87pub fn default_json(version: i16) -> ::serde_json::Value {
88    let mut obj = ::serde_json::Map::new();
89    obj.insert("groupId".to_string(), ::serde_json::Value::String(String::new()));
90    obj.insert("generationId".to_string(), ::serde_json::json!(0));
91    obj.insert("memberId".to_string(), ::serde_json::Value::String(String::new()));
92    if version >= 3 {
93        obj.insert("groupInstanceId".to_string(), ::serde_json::Value::Null);
94    }
95    ::serde_json::Value::Object(obj)
96}
97
98impl crate::ProtocolRequest for HeartbeatRequest {
99    const API_KEY: i16 = API_KEY;
100    const MIN_VERSION: i16 = MIN_VERSION;
101    const MAX_VERSION: i16 = MAX_VERSION;
102    const FLEXIBLE_MIN: i16 = FLEXIBLE_MIN;
103    type Response = super::heartbeat_response::HeartbeatResponse;
104}