Skip to main content

crabka_protocol/opt/rustwide/workdir/generated/
DescribeUserScramCredentialsRequest.owned.rs

1// AUTO-GENERATED by crabka-protocol-codegen against a9ce3221537b8653448750697915607dc7936cf3. Do not edit.
2
3use bytes::{Buf, BufMut};
4use crate::primitives::string_bytes::{
5    compact_string_len, get_compact_string_owned, get_string_owned,
6    put_compact_string, put_string, string_len,
7};
8use crate::tagged_fields::{read_tagged_fields, tagged_fields_len, WriteTaggedFields};
9use crate::{Decode, Encode, ProtocolError, UnknownTaggedFields};
10
11pub const API_KEY: i16 = 50;
12pub const MIN_VERSION: i16 = 0;
13pub const MAX_VERSION: i16 = 0;
14pub const FLEXIBLE_MIN: i16 = 0;
15
16#[inline]
17fn is_flexible(version: i16) -> bool { version >= FLEXIBLE_MIN }
18
19#[derive(Debug, Clone, PartialEq, Eq, Default)]
20pub struct DescribeUserScramCredentialsRequest {
21    pub users: Option<Vec<UserName>>,
22    pub unknown_tagged_fields: UnknownTaggedFields,
23}
24
25impl Encode for DescribeUserScramCredentialsRequest {
26    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
27        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
28            return Err(ProtocolError::UnsupportedVersion { api_key: API_KEY, version });
29        }
30        let flex = is_flexible(version);
31        if version >= 0 { { let len = (self.users).as_ref().map(Vec::len); crate::primitives::array::put_nullable_array_len(buf, len, flex); if let Some(v) = &self.users { for it in v { it.encode(buf, version)?; } } } }
32        if flex {
33            let tagged = WriteTaggedFields::new();
34            tagged.write(buf, &self.unknown_tagged_fields);
35        }
36        Ok(())
37    }
38    fn encoded_len(&self, version: i16) -> usize {
39        let flex = is_flexible(version);
40        let mut n: usize = 0;
41        if version >= 0 { n += { let opt: Option<&Vec<_>> = (self.users).as_ref(); let prefix = crate::primitives::array::nullable_array_len_prefix_len(opt.map(|v| v.len()), flex); let body: usize = opt.map_or(0, |v| v.iter().map(|it| it.encoded_len(version)).sum()); prefix + body }; }
42        if flex {
43            let known_pairs: Vec<(u32, usize)> = Vec::new();
44            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
45        }
46        n
47    }
48}
49
50impl<'de> Decode<'de> for DescribeUserScramCredentialsRequest {
51    fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
52        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
53            return Err(ProtocolError::UnsupportedVersion { api_key: API_KEY, version });
54        }
55        let flex = is_flexible(version);
56        let mut out = Self::default();
57        if version >= 0 { out.users = { let opt = crate::primitives::array::get_nullable_array_len(buf, flex)?; match opt { None => None, Some(n) => { let mut v = Vec::with_capacity(n); for _ in 0..n { v.push(UserName::decode(buf, version)?); } Some(v) } } }; }
58        if flex {
59            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| {
60                Ok(false)
61            })?;
62        }
63        Ok(out)
64    }
65}
66
67#[derive(Debug, Clone, PartialEq, Eq, Default)]
68pub struct UserName {
69    pub name: String,
70    pub unknown_tagged_fields: UnknownTaggedFields,
71}
72
73impl Encode for UserName {
74    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
75        let flex = version >= 0;
76        if version >= 0 { if flex { put_compact_string(buf, &self.name) } else { put_string(buf, &self.name) } }
77        if flex {
78            let tagged = WriteTaggedFields::new();
79            tagged.write(buf, &self.unknown_tagged_fields);
80        }
81        Ok(())
82    }
83    fn encoded_len(&self, version: i16) -> usize {
84        let flex = version >= 0;
85        let mut n: usize = 0;
86        if version >= 0 { n += if flex { compact_string_len(&self.name) } else { string_len(&self.name) }; }
87        if flex {
88            let known_pairs: Vec<(u32, usize)> = Vec::new();
89            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
90        }
91        n
92    }
93}
94
95impl<'de> Decode<'de> for UserName {
96    fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
97        let flex = version >= 0;
98        let mut out = Self::default();
99        if version >= 0 { out.name = if flex { get_compact_string_owned(buf)? } else { get_string_owned(buf)? }; }
100        if flex {
101            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| {
102                Ok(false)
103            })?;
104        }
105        Ok(out)
106    }
107}
108
109/// Default JSON payload matching `Self::default()` for JVM oracle differential testing.
110/// Only includes fields valid for the given version.
111#[must_use]
112#[allow(unused_comparisons)]
113pub fn default_json(version: i16) -> ::serde_json::Value {
114    let mut obj = ::serde_json::Map::new();
115    obj.insert("users".to_string(), ::serde_json::Value::Null);
116    ::serde_json::Value::Object(obj)
117}
118
119impl crate::ProtocolRequest for DescribeUserScramCredentialsRequest {
120    const API_KEY: i16 = API_KEY;
121    const MIN_VERSION: i16 = MIN_VERSION;
122    const MAX_VERSION: i16 = MAX_VERSION;
123    const FLEXIBLE_MIN: i16 = FLEXIBLE_MIN;
124    type Response = super::describe_user_scram_credentials_response::DescribeUserScramCredentialsResponse;
125}