Skip to main content

krabka_protocol/opt/rustwide/workdir/generated/
OffsetCommitKey.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};
15pub const MIN_VERSION: i16 = 0;
16pub const MAX_VERSION: i16 = 0;
17pub const FLEXIBLE_MIN: i16 = 32767;
18#[inline]
19#[must_use]
20pub fn is_flexible(version: i16) -> bool {
21    version == FLEXIBLE_MIN
22}
23#[derive(Debug, Clone, PartialEq, Eq, Default)]
24pub struct OffsetCommitKey {
25    pub group: String,
26    pub topic: String,
27    pub partition: i32,
28    pub unknown_tagged_fields: UnknownTaggedFields,
29}
30impl Encode for OffsetCommitKey {
31    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
32        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
33            return Err(ProtocolError::SchemaMismatch(
34                "OffsetCommitKey version out of range",
35            ));
36        }
37        let flex = is_flexible(version);
38        if version == 0 {
39            if flex {
40                let () = put_compact_string(buf, &self.group);
41            } else {
42                let () = put_string(buf, &self.group);
43            }
44        }
45        if version == 0 {
46            if flex {
47                let () = put_compact_string(buf, &self.topic);
48            } else {
49                let () = put_string(buf, &self.topic);
50            }
51        }
52        if version == 0 {
53            put_i32(buf, self.partition);
54        }
55        Ok(())
56    }
57    fn encoded_len(&self, version: i16) -> usize {
58        let flex = is_flexible(version);
59        let mut n: usize = 0;
60        if version == 0 {
61            n += if flex {
62                compact_string_len(&self.group)
63            } else {
64                string_len(&self.group)
65            };
66        }
67        if version == 0 {
68            n += if flex {
69                compact_string_len(&self.topic)
70            } else {
71                string_len(&self.topic)
72            };
73        }
74        if version == 0 {
75            n += 4;
76        }
77        n
78    }
79}
80impl Decode<'_> for OffsetCommitKey {
81    fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
82        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
83            return Err(ProtocolError::SchemaMismatch(
84                "OffsetCommitKey version out of range",
85            ));
86        }
87        let flex = is_flexible(version);
88        let mut out = Self::default();
89        if version == 0 {
90            out.group = if flex {
91                get_compact_string_owned(buf)?
92            } else {
93                get_string_owned(buf)?
94            };
95        }
96        if version == 0 {
97            out.topic = if flex {
98                get_compact_string_owned(buf)?
99            } else {
100                get_string_owned(buf)?
101            };
102        }
103        if version == 0 {
104            out.partition = get_i32(buf)?;
105        }
106        Ok(out)
107    }
108}
109#[cfg(test)]
110impl OffsetCommitKey {
111    #[must_use]
112    pub fn populated(version: i16) -> Self {
113        let mut m = Self::default();
114        if version == 0 {
115            m.group = "x".to_string();
116        }
117        if version == 0 {
118            m.topic = "x".to_string();
119        }
120        if version == 0 {
121            m.partition = 1i32;
122        }
123        m
124    }
125}
126/// Default JSON payload matching `Self::default()` for JVM oracle differential testing.
127/// Only includes fields valid for the given version.
128#[must_use]
129#[allow(unused_comparisons)]
130pub fn default_json(version: i16) -> ::serde_json::Value {
131    let mut obj = ::serde_json::Map::new();
132    if version <= 0 {
133        obj.insert(
134            "group".to_string(),
135            ::serde_json::Value::String(String::new()),
136        );
137    }
138    if version <= 0 {
139        obj.insert(
140            "topic".to_string(),
141            ::serde_json::Value::String(String::new()),
142        );
143    }
144    if version <= 0 {
145        obj.insert("partition".to_string(), ::serde_json::json!(0));
146    }
147    ::serde_json::Value::Object(obj)
148}