Skip to main content

crabka_protocol/opt/rustwide/workdir/generated/
AllocateProducerIdsResponse.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, get_i64, put_i16, put_i32, put_i64};
6use crate::tagged_fields::{read_tagged_fields, tagged_fields_len, WriteTaggedFields};
7use crate::{Decode, Encode, ProtocolError, UnknownTaggedFields};
8
9pub const API_KEY: i16 = 67;
10pub const MIN_VERSION: i16 = 0;
11pub const MAX_VERSION: i16 = 0;
12pub const FLEXIBLE_MIN: i16 = 0;
13
14#[inline]
15fn is_flexible(version: i16) -> bool { version >= FLEXIBLE_MIN }
16
17#[derive(Debug, Clone, PartialEq, Eq, Default)]
18pub struct AllocateProducerIdsResponse {
19    pub throttle_time_ms: i32,
20    pub error_code: i16,
21    pub producer_id_start: i64,
22    pub producer_id_len: i32,
23    pub unknown_tagged_fields: UnknownTaggedFields,
24}
25
26impl Encode for AllocateProducerIdsResponse {
27    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
28        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
29            return Err(ProtocolError::UnsupportedVersion { api_key: API_KEY, version });
30        }
31        let flex = is_flexible(version);
32        if version >= 0 { put_i32(buf, self.throttle_time_ms) }
33        if version >= 0 { put_i16(buf, self.error_code) }
34        if version >= 0 { put_i64(buf, self.producer_id_start) }
35        if version >= 0 { put_i32(buf, self.producer_id_len) }
36        if flex {
37            let tagged = WriteTaggedFields::new();
38            tagged.write(buf, &self.unknown_tagged_fields);
39        }
40        Ok(())
41    }
42    fn encoded_len(&self, version: i16) -> usize {
43        let flex = is_flexible(version);
44        let mut n: usize = 0;
45        if version >= 0 { n += 4; }
46        if version >= 0 { n += 2; }
47        if version >= 0 { n += 8; }
48        if version >= 0 { n += 4; }
49        if flex {
50            let known_pairs: Vec<(u32, usize)> = Vec::new();
51            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
52        }
53        n
54    }
55}
56
57impl<'de> Decode<'de> for AllocateProducerIdsResponse {
58    fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
59        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
60            return Err(ProtocolError::UnsupportedVersion { api_key: API_KEY, version });
61        }
62        let flex = is_flexible(version);
63        let mut out = Self::default();
64        if version >= 0 { out.throttle_time_ms = get_i32(buf)?; }
65        if version >= 0 { out.error_code = get_i16(buf)?; }
66        if version >= 0 { out.producer_id_start = get_i64(buf)?; }
67        if version >= 0 { out.producer_id_len = get_i32(buf)?; }
68        if flex {
69            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| {
70                Ok(false)
71            })?;
72        }
73        Ok(out)
74    }
75}
76
77/// Default JSON payload matching `Self::default()` for JVM oracle differential testing.
78/// Only includes fields valid for the given version.
79#[must_use]
80#[allow(unused_comparisons)]
81pub fn default_json(version: i16) -> ::serde_json::Value {
82    let mut obj = ::serde_json::Map::new();
83    obj.insert("throttleTimeMs".to_string(), ::serde_json::json!(0));
84    obj.insert("errorCode".to_string(), ::serde_json::json!(0));
85    obj.insert("producerIdStart".to_string(), ::serde_json::json!(0));
86    obj.insert("producerIdLen".to_string(), ::serde_json::json!(0));
87    ::serde_json::Value::Object(obj)
88}