Skip to main content

krabka_protocol/opt/rustwide/workdir/generated/
ListConfigResourcesRequest.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::fixed::{get_i8, put_i8},
8    tagged_fields::{WriteTaggedFields, read_tagged_fields, tagged_fields_len},
9};
10pub const API_KEY: i16 = 74;
11pub const MIN_VERSION: i16 = 0;
12pub const MAX_VERSION: i16 = 1;
13pub const LATEST_STABLE_VERSION: i16 = 1;
14pub const FLEXIBLE_MIN: i16 = 0;
15#[inline]
16#[must_use]
17pub fn is_flexible(version: i16) -> bool {
18    version >= FLEXIBLE_MIN
19}
20#[derive(Debug, Clone, PartialEq, Eq, Default)]
21pub struct ListConfigResourcesRequest {
22    pub resource_types: Vec<i8>,
23    pub unknown_tagged_fields: UnknownTaggedFields,
24}
25impl Encode for ListConfigResourcesRequest {
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 {
29                api_key: API_KEY,
30                version,
31            });
32        }
33        let flex = is_flexible(version);
34        if version >= 1 {
35            {
36                crate::primitives::array::put_array_len(buf, (self.resource_types).len(), flex);
37                for it in &self.resource_types {
38                    put_i8(buf, *it);
39                }
40            };
41        }
42        if flex {
43            let tagged = WriteTaggedFields::new();
44            tagged.write(buf, &self.unknown_tagged_fields);
45        }
46        Ok(())
47    }
48    fn encoded_len(&self, version: i16) -> usize {
49        let flex = is_flexible(version);
50        let mut n: usize = 0;
51        if version >= 1 {
52            n += {
53                let prefix = crate::primitives::array::array_len_prefix_len(
54                    (self.resource_types).len(),
55                    flex,
56                );
57                let body: usize = (self.resource_types).iter().map(|_| 1).sum();
58                prefix + body
59            };
60        }
61        if flex {
62            let known_pairs: Vec<(u32, usize)> = Vec::new();
63            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
64        }
65        n
66    }
67}
68impl Decode<'_> for ListConfigResourcesRequest {
69    fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
70        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
71            return Err(ProtocolError::UnsupportedVersion {
72                api_key: API_KEY,
73                version,
74            });
75        }
76        let flex = is_flexible(version);
77        let mut out = Self::default();
78        if version >= 1 {
79            out.resource_types = {
80                let n = crate::primitives::array::get_array_len(buf, flex)?;
81                let mut v = Vec::with_capacity(n);
82                for _ in 0..n {
83                    v.push(get_i8(buf)?);
84                }
85                v
86            };
87        }
88        if flex {
89            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
90        }
91        Ok(out)
92    }
93}
94#[cfg(test)]
95impl ListConfigResourcesRequest {
96    #[must_use]
97    pub fn populated(version: i16) -> Self {
98        let mut m = Self::default();
99        if version >= 1 {
100            m.resource_types = vec![1i8];
101        }
102        m
103    }
104}
105/// Default JSON payload matching `Self::default()` for JVM oracle differential testing.
106/// Only includes fields valid for the given version.
107#[must_use]
108#[allow(unused_comparisons)]
109pub fn default_json(version: i16) -> ::serde_json::Value {
110    let mut obj = ::serde_json::Map::new();
111    if version >= 1 {
112        obj.insert(
113            "resourceTypes".to_string(),
114            ::serde_json::Value::Array(vec![]),
115        );
116    }
117    ::serde_json::Value::Object(obj)
118}
119impl crate::ProtocolRequest for ListConfigResourcesRequest {
120    const API_KEY: i16 = API_KEY;
121    const MIN_VERSION: i16 = MIN_VERSION;
122    const MAX_VERSION: i16 = MAX_VERSION;
123    const LATEST_STABLE_VERSION: i16 = LATEST_STABLE_VERSION;
124    const FLEXIBLE_MIN: i16 = FLEXIBLE_MIN;
125    type Response = super::list_config_resources_response::ListConfigResourcesResponse;
126}