Skip to main content

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

1// AUTO-GENERATED by crabka-protocol-codegen against a9ce3221537b8653448750697915607dc7936cf3. Do not edit.
2
3use bytes::{Buf, BufMut};
4
5use crate::primitives::fixed::{get_bool, put_bool};
6use crate::primitives::string_bytes::{
7    compact_string_len, get_compact_string_owned, get_string_owned,
8    put_compact_string, put_string, string_len,
9};
10use crate::tagged_fields::{read_tagged_fields, tagged_fields_len, WriteTaggedFields};
11use crate::{Decode, Encode, ProtocolError, UnknownTaggedFields};
12
13pub const API_KEY: i16 = 15;
14pub const MIN_VERSION: i16 = 0;
15pub const MAX_VERSION: i16 = 6;
16pub const FLEXIBLE_MIN: i16 = 5;
17
18#[inline]
19fn is_flexible(version: i16) -> bool { version >= FLEXIBLE_MIN }
20
21#[derive(Debug, Clone, PartialEq, Eq, Default)]
22pub struct DescribeGroupsRequest {
23    pub groups: Vec<String>,
24    pub include_authorized_operations: bool,
25    pub unknown_tagged_fields: UnknownTaggedFields,
26}
27
28impl Encode for DescribeGroupsRequest {
29    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
30        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
31            return Err(ProtocolError::UnsupportedVersion { api_key: API_KEY, version });
32        }
33        let flex = is_flexible(version);
34        if version >= 0 { { crate::primitives::array::put_array_len(buf, (self.groups).len(), flex); for it in &self.groups { if flex { put_compact_string(buf, &*it) } else { put_string(buf, &*it) }; } } }
35        if version >= 3 { put_bool(buf, self.include_authorized_operations) }
36        if flex {
37            let tagged = WriteTaggedFields::new();
38            tagged.write(buf, &self.unknown_tagged_fields);
39        }
40        Ok(())
41    }
42    fn encoded_len(&self, version: i16) -> usize {
43        let flex = is_flexible(version);
44        let mut n: usize = 0;
45        if version >= 0 { n += { let prefix = crate::primitives::array::array_len_prefix_len((self.groups).len(), flex); let body: usize = (self.groups).iter().map(|it| if flex { compact_string_len(&*it) } else { string_len(&*it) }).sum(); prefix + body }; }
46        if version >= 3 { n += 1; }
47        if flex {
48            let known_pairs: Vec<(u32, usize)> = Vec::new();
49            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
50        }
51        n
52    }
53}
54
55impl<'de> Decode<'de> for DescribeGroupsRequest {
56    fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
57        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
58            return Err(ProtocolError::UnsupportedVersion { api_key: API_KEY, version });
59        }
60        let flex = is_flexible(version);
61        let mut out = Self::default();
62        if version >= 0 { out.groups = { let n = crate::primitives::array::get_array_len(buf, flex)?; let mut v = Vec::with_capacity(n); for _ in 0..n { v.push(if flex { get_compact_string_owned(buf)? } else { get_string_owned(buf)? }); } v }; }
63        if version >= 3 { out.include_authorized_operations = get_bool(buf)?; }
64        if flex {
65            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| {
66                Ok(false)
67            })?;
68        }
69        Ok(out)
70    }
71}
72
73/// Default JSON payload matching `Self::default()` for JVM oracle differential testing.
74/// Only includes fields valid for the given version.
75#[must_use]
76#[allow(unused_comparisons)]
77pub fn default_json(version: i16) -> ::serde_json::Value {
78    let mut obj = ::serde_json::Map::new();
79    obj.insert("groups".to_string(), ::serde_json::Value::Array(vec![]));
80    if version >= 3 {
81        obj.insert("includeAuthorizedOperations".to_string(), ::serde_json::Value::Bool(false));
82    }
83    ::serde_json::Value::Object(obj)
84}
85
86impl crate::ProtocolRequest for DescribeGroupsRequest {
87    const API_KEY: i16 = API_KEY;
88    const MIN_VERSION: i16 = MIN_VERSION;
89    const MAX_VERSION: i16 = MAX_VERSION;
90    const FLEXIBLE_MIN: i16 = FLEXIBLE_MIN;
91    type Response = super::describe_groups_response::DescribeGroupsResponse;
92}