Skip to main content

krabka_protocol/opt/rustwide/workdir/generated/
RemoveUserScramCredentialRecord.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_i8, put_i8},
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 MIN_VERSION: i16 = 0;
17pub const MAX_VERSION: i16 = 0;
18pub const FLEXIBLE_MIN: i16 = 0;
19#[inline]
20#[must_use]
21pub fn is_flexible(version: i16) -> bool {
22    version >= FLEXIBLE_MIN
23}
24#[derive(Debug, Clone, PartialEq, Eq, Default)]
25pub struct RemoveUserScramCredentialRecord {
26    pub name: String,
27    pub mechanism: i8,
28    pub unknown_tagged_fields: UnknownTaggedFields,
29}
30impl Encode for RemoveUserScramCredentialRecord {
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                "RemoveUserScramCredentialRecord 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.name);
41            } else {
42                let () = put_string(buf, &self.name);
43            }
44        }
45        if version >= 0 {
46            put_i8(buf, self.mechanism);
47        }
48        if flex {
49            let tagged = WriteTaggedFields::new();
50            tagged.write(buf, &self.unknown_tagged_fields);
51        }
52        Ok(())
53    }
54    fn encoded_len(&self, version: i16) -> usize {
55        let flex = is_flexible(version);
56        let mut n: usize = 0;
57        if version >= 0 {
58            n += if flex {
59                compact_string_len(&self.name)
60            } else {
61                string_len(&self.name)
62            };
63        }
64        if version >= 0 {
65            n += 1;
66        }
67        if flex {
68            let known_pairs: Vec<(u32, usize)> = Vec::new();
69            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
70        }
71        n
72    }
73}
74impl Decode<'_> for RemoveUserScramCredentialRecord {
75    fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
76        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
77            return Err(ProtocolError::SchemaMismatch(
78                "RemoveUserScramCredentialRecord version out of range",
79            ));
80        }
81        let flex = is_flexible(version);
82        let mut out = Self::default();
83        if version >= 0 {
84            out.name = if flex {
85                get_compact_string_owned(buf)?
86            } else {
87                get_string_owned(buf)?
88            };
89        }
90        if version >= 0 {
91            out.mechanism = get_i8(buf)?;
92        }
93        if flex {
94            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
95        }
96        Ok(out)
97    }
98}
99#[cfg(test)]
100impl RemoveUserScramCredentialRecord {
101    #[must_use]
102    pub fn populated(version: i16) -> Self {
103        let mut m = Self::default();
104        if version >= 0 {
105            m.name = "x".to_string();
106        }
107        if version >= 0 {
108            m.mechanism = 1i8;
109        }
110        m
111    }
112}
113/// Default JSON payload matching `Self::default()` for JVM oracle differential testing.
114/// Only includes fields valid for the given version.
115#[must_use]
116#[allow(unused_comparisons)]
117pub fn default_json(_version: i16) -> ::serde_json::Value {
118    let mut obj = ::serde_json::Map::new();
119    obj.insert(
120        "name".to_string(),
121        ::serde_json::Value::String(String::new()),
122    );
123    obj.insert("mechanism".to_string(), ::serde_json::json!(0));
124    ::serde_json::Value::Object(obj)
125}