Skip to main content

krabka_protocol/opt/rustwide/workdir/generated/
StreamsGroupTopologyDescriptionUpdateRequest.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_i32, put_i32},
9        string_bytes::{
10            compact_string_len, get_compact_string_owned, get_string_owned, put_compact_string,
11            put_string, string_len,
12        },
13    },
14    tagged_fields::{WriteTaggedFields, read_tagged_fields, tagged_fields_len},
15};
16pub const API_KEY: i16 = 93;
17pub const MIN_VERSION: i16 = 0;
18pub const MAX_VERSION: i16 = 0;
19pub const LATEST_STABLE_VERSION: i16 = 0;
20pub const FLEXIBLE_MIN: i16 = 0;
21#[inline]
22#[must_use]
23pub fn is_flexible(version: i16) -> bool {
24    version >= FLEXIBLE_MIN
25}
26#[derive(Debug, Clone, PartialEq, Eq, Default)]
27pub struct StreamsGroupTopologyDescriptionUpdateRequest {
28    pub group_id: String,
29    pub member_id: String,
30    pub topology_epoch: i32,
31    pub topology_description: super::common::streams_group_topology_description_update_request::topology_description::TopologyDescription,
32    pub unknown_tagged_fields: UnknownTaggedFields,
33}
34impl Encode for StreamsGroupTopologyDescriptionUpdateRequest {
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 {
38                api_key: API_KEY,
39                version,
40            });
41        }
42        let flex = is_flexible(version);
43        if version >= 0 {
44            if flex {
45                let () = put_compact_string(buf, &self.group_id);
46            } else {
47                let () = put_string(buf, &self.group_id);
48            }
49        }
50        if version >= 0 {
51            if flex {
52                let () = put_compact_string(buf, &self.member_id);
53            } else {
54                let () = put_string(buf, &self.member_id);
55            }
56        }
57        if version >= 0 {
58            put_i32(buf, self.topology_epoch);
59        }
60        if version >= 0 {
61            self.topology_description.encode(buf, version)?;
62        }
63        if flex {
64            let tagged = WriteTaggedFields::new();
65            tagged.write(buf, &self.unknown_tagged_fields);
66        }
67        Ok(())
68    }
69    fn encoded_len(&self, version: i16) -> usize {
70        let flex = is_flexible(version);
71        let mut n: usize = 0;
72        if version >= 0 {
73            n += if flex {
74                compact_string_len(&self.group_id)
75            } else {
76                string_len(&self.group_id)
77            };
78        }
79        if version >= 0 {
80            n += if flex {
81                compact_string_len(&self.member_id)
82            } else {
83                string_len(&self.member_id)
84            };
85        }
86        if version >= 0 {
87            n += 4;
88        }
89        if version >= 0 {
90            n += self.topology_description.encoded_len(version);
91        }
92        if flex {
93            let known_pairs: Vec<(u32, usize)> = Vec::new();
94            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
95        }
96        n
97    }
98}
99impl Decode<'_> for StreamsGroupTopologyDescriptionUpdateRequest {
100    fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
101        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
102            return Err(ProtocolError::UnsupportedVersion {
103                api_key: API_KEY,
104                version,
105            });
106        }
107        let flex = is_flexible(version);
108        let mut out = Self::default();
109        if version >= 0 {
110            out.group_id = if flex {
111                get_compact_string_owned(buf)?
112            } else {
113                get_string_owned(buf)?
114            };
115        }
116        if version >= 0 {
117            out.member_id = if flex {
118                get_compact_string_owned(buf)?
119            } else {
120                get_string_owned(buf)?
121            };
122        }
123        if version >= 0 {
124            out.topology_epoch = get_i32(buf)?;
125        }
126        if version >= 0 {
127            out.topology_description = super::common::streams_group_topology_description_update_request::topology_description::TopologyDescription::decode(buf, version)?;
128        }
129        if flex {
130            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
131        }
132        Ok(out)
133    }
134}
135#[cfg(test)]
136impl StreamsGroupTopologyDescriptionUpdateRequest {
137    #[must_use]
138    pub fn populated(version: i16) -> Self {
139        let mut m = Self::default();
140        if version >= 0 {
141            m.group_id = "x".to_string();
142        }
143        if version >= 0 {
144            m.member_id = "x".to_string();
145        }
146        if version >= 0 {
147            m.topology_epoch = 1i32;
148        }
149        if version >= 0 {
150            m.topology_description = super::common::streams_group_topology_description_update_request::topology_description::TopologyDescription::populated(version);
151        }
152        m
153    }
154}
155/// Default JSON payload matching `Self::default()` for JVM oracle differential testing.
156/// Only includes fields valid for the given version.
157#[must_use]
158#[allow(unused_comparisons)]
159pub fn default_json(_version: i16) -> ::serde_json::Value {
160    let mut obj = ::serde_json::Map::new();
161    obj.insert(
162        "groupId".to_string(),
163        ::serde_json::Value::String(String::new()),
164    );
165    obj.insert(
166        "memberId".to_string(),
167        ::serde_json::Value::String(String::new()),
168    );
169    obj.insert("topologyEpoch".to_string(), ::serde_json::json!(0));
170    obj.insert(
171        "topologyDescription".to_string(),
172        ::serde_json::Value::Object(::serde_json::Map::new()),
173    );
174    ::serde_json::Value::Object(obj)
175}
176impl crate::ProtocolRequest for StreamsGroupTopologyDescriptionUpdateRequest {
177    const API_KEY: i16 = API_KEY;
178    const MIN_VERSION: i16 = MIN_VERSION;
179    const MAX_VERSION: i16 = MAX_VERSION;
180    const LATEST_STABLE_VERSION: i16 = LATEST_STABLE_VERSION;
181    const FLEXIBLE_MIN: i16 = FLEXIBLE_MIN;
182    type Response = super::streams_group_topology_description_update_response::StreamsGroupTopologyDescriptionUpdateResponse;
183}