Skip to main content

crabka_protocol/opt/rustwide/workdir/generated/
SyncGroupResponse.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_i16, get_i32, put_i16, 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 SyncGroupResponse {
26    pub throttle_time_ms: i32,
27    pub error_code: i16,
28    pub protocol_type: Option<String>,
29    pub protocol_name: Option<String>,
30    pub assignment: ::bytes::Bytes,
31    pub unknown_tagged_fields: UnknownTaggedFields,
32}
33
34impl Encode for SyncGroupResponse {
35    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
36        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
37            return Err(ProtocolError::UnsupportedVersion { api_key: API_KEY, version });
38        }
39        let flex = is_flexible(version);
40        if version >= 1 { put_i32(buf, self.throttle_time_ms) }
41        if version >= 0 { put_i16(buf, self.error_code) }
42        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()) } }
43        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()) } }
44        if version >= 0 { if flex { put_compact_bytes(buf, &self.assignment) } else { put_bytes(buf, &self.assignment) } }
45        if flex {
46            let tagged = WriteTaggedFields::new();
47            tagged.write(buf, &self.unknown_tagged_fields);
48        }
49        Ok(())
50    }
51    fn encoded_len(&self, version: i16) -> usize {
52        let flex = is_flexible(version);
53        let mut n: usize = 0;
54        if version >= 1 { n += 4; }
55        if version >= 0 { n += 2; }
56        if version >= 5 { n += if flex { compact_nullable_string_len(self.protocol_type.as_deref()) } else { nullable_string_len(self.protocol_type.as_deref()) }; }
57        if version >= 5 { n += if flex { compact_nullable_string_len(self.protocol_name.as_deref()) } else { nullable_string_len(self.protocol_name.as_deref()) }; }
58        if version >= 0 { n += if flex { compact_bytes_len(&self.assignment) } else { bytes_len(&self.assignment) }; }
59        if flex {
60            let known_pairs: Vec<(u32, usize)> = Vec::new();
61            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
62        }
63        n
64    }
65}
66
67impl<'de> Decode<'de> for SyncGroupResponse {
68    fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
69        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
70            return Err(ProtocolError::UnsupportedVersion { api_key: API_KEY, version });
71        }
72        let flex = is_flexible(version);
73        let mut out = Self::default();
74        if version >= 1 { out.throttle_time_ms = get_i32(buf)?; }
75        if version >= 0 { out.error_code = get_i16(buf)?; }
76        if version >= 5 { out.protocol_type = if flex { get_compact_nullable_string_owned(buf)? } else { get_nullable_string_owned(buf)? }; }
77        if version >= 5 { out.protocol_name = if flex { get_compact_nullable_string_owned(buf)? } else { get_nullable_string_owned(buf)? }; }
78        if version >= 0 { out.assignment = if flex { get_compact_bytes_owned(buf)? } else { get_bytes_owned(buf)? }; }
79        if flex {
80            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| {
81                Ok(false)
82            })?;
83        }
84        Ok(out)
85    }
86}
87
88/// Default JSON payload matching `Self::default()` for JVM oracle differential testing.
89/// Only includes fields valid for the given version.
90#[must_use]
91#[allow(unused_comparisons)]
92pub fn default_json(version: i16) -> ::serde_json::Value {
93    let mut obj = ::serde_json::Map::new();
94    if version >= 1 {
95        obj.insert("throttleTimeMs".to_string(), ::serde_json::json!(0));
96    }
97    obj.insert("errorCode".to_string(), ::serde_json::json!(0));
98    if version >= 5 {
99        obj.insert("protocolType".to_string(), ::serde_json::Value::Null);
100    }
101    if version >= 5 {
102        obj.insert("protocolName".to_string(), ::serde_json::Value::Null);
103    }
104    obj.insert("assignment".to_string(), ::serde_json::Value::String(String::new()));
105    ::serde_json::Value::Object(obj)
106}