Skip to main content

krabka_protocol/opt/rustwide/workdir/generated/
StreamsGroupTopologyDescriptionUpdateResponse.borrowed.rs

1// AUTO-GENERATED by krabka-protocol-codegen against a9ce3221537b8653448750697915607dc7936cf3. Do not edit.
2use bytes::BufMut;
3
4use crate::{
5    DecodeBorrow, Encode, ProtocolError, UnknownTaggedFields,
6    owned::streams_group_topology_description_update_response,
7    primitives::{
8        fixed::{get_i16, get_i32, put_i16, put_i32},
9        string_bytes::{
10            compact_nullable_string_len, nullable_string_len, put_compact_nullable_string,
11            put_nullable_string,
12        },
13        string_bytes_borrowed::{
14            get_compact_nullable_string_borrowed, get_nullable_string_borrowed,
15        },
16    },
17    tagged_fields::{WriteTaggedFields, read_tagged_fields, tagged_fields_len},
18};
19pub const API_KEY: i16 = 93;
20pub const MIN_VERSION: i16 = 0;
21pub const MAX_VERSION: i16 = 0;
22pub const FLEXIBLE_MIN: i16 = 0;
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 StreamsGroupTopologyDescriptionUpdateResponse<'a> {
30    pub throttle_time_ms: i32,
31    pub error_code: i16,
32    pub error_message: Option<&'a str>,
33    pub unknown_tagged_fields: UnknownTaggedFields,
34}
35impl StreamsGroupTopologyDescriptionUpdateResponse<'_> {
36    #[must_use]
37    pub fn to_owned(&self) -> streams_group_topology_description_update_response::StreamsGroupTopologyDescriptionUpdateResponse{
38        streams_group_topology_description_update_response::StreamsGroupTopologyDescriptionUpdateResponse {
39            throttle_time_ms: (self.throttle_time_ms),
40            error_code: (self.error_code),
41            error_message: (self.error_message).map(str::to_owned),
42            unknown_tagged_fields: self.unknown_tagged_fields.clone(),
43        }
44    }
45}
46impl Encode for StreamsGroupTopologyDescriptionUpdateResponse<'_> {
47    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
48        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
49            return Err(ProtocolError::UnsupportedVersion {
50                api_key: API_KEY,
51                version,
52            });
53        }
54        let flex = is_flexible(version);
55        if version >= 0 {
56            put_i32(buf, self.throttle_time_ms);
57        }
58        if version >= 0 {
59            put_i16(buf, self.error_code);
60        }
61        if version >= 0 {
62            if flex {
63                put_compact_nullable_string(buf, self.error_message)?;
64            } else {
65                put_nullable_string(buf, self.error_message)?;
66            }
67        }
68        if flex {
69            let tagged = WriteTaggedFields::new();
70            tagged.write(buf, &self.unknown_tagged_fields)?;
71        }
72        Ok(())
73    }
74    fn encoded_len(&self, version: i16) -> usize {
75        let flex = is_flexible(version);
76        let mut n: usize = 0;
77        if version >= 0 {
78            n += 4;
79        }
80        if version >= 0 {
81            n += 2;
82        }
83        if version >= 0 {
84            n += if flex {
85                compact_nullable_string_len(self.error_message)
86            } else {
87                nullable_string_len(self.error_message)
88            };
89        }
90        if flex {
91            let known_pairs: Vec<(u32, usize)> = Vec::new();
92            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
93        }
94        n
95    }
96}
97impl<'de> DecodeBorrow<'de> for StreamsGroupTopologyDescriptionUpdateResponse<'de> {
98    fn decode_borrow(buf: &mut &'de [u8], version: i16) -> Result<Self, ProtocolError> {
99        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
100            return Err(ProtocolError::UnsupportedVersion {
101                api_key: API_KEY,
102                version,
103            });
104        }
105        let flex = is_flexible(version);
106        let mut out = Self::default();
107        if version >= 0 {
108            out.throttle_time_ms = get_i32(buf)?;
109        }
110        if version >= 0 {
111            out.error_code = get_i16(buf)?;
112        }
113        if version >= 0 {
114            out.error_message = if flex {
115                get_compact_nullable_string_borrowed(buf)?
116            } else {
117                get_nullable_string_borrowed(buf)?
118            };
119        }
120        if flex {
121            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
122        }
123        Ok(out)
124    }
125}
126#[cfg(test)]
127impl StreamsGroupTopologyDescriptionUpdateResponse<'_> {
128    #[must_use]
129    pub fn populated(version: i16) -> Self {
130        let mut m = Self::default();
131        if version >= 0 {
132            m.throttle_time_ms = 1i32;
133        }
134        if version >= 0 {
135            m.error_code = 1i16;
136        }
137        if version >= 0 {
138            m.error_message = Some("x");
139        }
140        m
141    }
142}