Skip to main content

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