Skip to main content

krabka_protocol/opt/rustwide/workdir/generated/
UnregisterControllerRequest.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_i32, put_i32},
8    tagged_fields::{WriteTaggedFields, read_tagged_fields, tagged_fields_len},
9};
10pub const API_KEY: i16 = 94;
11pub const MIN_VERSION: i16 = 0;
12pub const MAX_VERSION: i16 = 0;
13pub const LATEST_STABLE_VERSION: i16 = 0;
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 UnregisterControllerRequest {
22    pub controller_id: i32,
23    pub unknown_tagged_fields: UnknownTaggedFields,
24}
25impl Encode for UnregisterControllerRequest {
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 >= 0 {
35            put_i32(buf, self.controller_id);
36        }
37        if flex {
38            let tagged = WriteTaggedFields::new();
39            tagged.write(buf, &self.unknown_tagged_fields);
40        }
41        Ok(())
42    }
43    fn encoded_len(&self, version: i16) -> usize {
44        let flex = is_flexible(version);
45        let mut n: usize = 0;
46        if version >= 0 {
47            n += 4;
48        }
49        if flex {
50            let known_pairs: Vec<(u32, usize)> = Vec::new();
51            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
52        }
53        n
54    }
55}
56impl Decode<'_> for UnregisterControllerRequest {
57    fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
58        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
59            return Err(ProtocolError::UnsupportedVersion {
60                api_key: API_KEY,
61                version,
62            });
63        }
64        let flex = is_flexible(version);
65        let mut out = Self::default();
66        if version >= 0 {
67            out.controller_id = get_i32(buf)?;
68        }
69        if flex {
70            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
71        }
72        Ok(out)
73    }
74}
75#[cfg(test)]
76impl UnregisterControllerRequest {
77    #[must_use]
78    pub fn populated(version: i16) -> Self {
79        let mut m = Self::default();
80        if version >= 0 {
81            m.controller_id = 1i32;
82        }
83        m
84    }
85}
86/// Default JSON payload matching `Self::default()` for JVM oracle differential testing.
87/// Only includes fields valid for the given version.
88#[must_use]
89#[allow(unused_comparisons)]
90pub fn default_json(_version: i16) -> ::serde_json::Value {
91    let mut obj = ::serde_json::Map::new();
92    obj.insert("controllerId".to_string(), ::serde_json::json!(0));
93    ::serde_json::Value::Object(obj)
94}
95impl crate::ProtocolRequest for UnregisterControllerRequest {
96    const API_KEY: i16 = API_KEY;
97    const MIN_VERSION: i16 = MIN_VERSION;
98    const MAX_VERSION: i16 = MAX_VERSION;
99    const LATEST_STABLE_VERSION: i16 = LATEST_STABLE_VERSION;
100    const FLEXIBLE_MIN: i16 = FLEXIBLE_MIN;
101    type Response = super::unregister_controller_response::UnregisterControllerResponse;
102}