Skip to main content

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

1// AUTO-GENERATED by crabka-protocol-codegen against a9ce3221537b8653448750697915607dc7936cf3. Do not edit.
2
3use crate::tagged_fields::{WriteTaggedFields, read_tagged_fields, tagged_fields_len};
4use crate::{Decode, Encode, ProtocolError, UnknownTaggedFields};
5use bytes::{Buf, BufMut};
6pub const API_KEY: i16 = 71;
7pub const MIN_VERSION: i16 = 0;
8pub const MAX_VERSION: i16 = 0;
9pub const FLEXIBLE_MIN: i16 = 0;
10#[inline]
11fn is_flexible(version: i16) -> bool {
12    version >= FLEXIBLE_MIN
13}
14#[derive(Debug, Clone, PartialEq, Eq, Default)]
15pub struct GetTelemetrySubscriptionsRequest {
16    pub client_instance_id: crate::primitives::uuid::Uuid,
17    pub unknown_tagged_fields: UnknownTaggedFields,
18}
19impl Encode for GetTelemetrySubscriptionsRequest {
20    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
21        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
22            return Err(ProtocolError::UnsupportedVersion {
23                api_key: API_KEY,
24                version,
25            });
26        }
27        let flex = is_flexible(version);
28        if version >= 0 {
29            crate::primitives::uuid::put_uuid(buf, self.client_instance_id);
30        }
31        if flex {
32            let tagged = WriteTaggedFields::new();
33            tagged.write(buf, &self.unknown_tagged_fields);
34        }
35        Ok(())
36    }
37    fn encoded_len(&self, version: i16) -> usize {
38        let flex = is_flexible(version);
39        let mut n: usize = 0;
40        if version >= 0 {
41            n += 16;
42        }
43        if flex {
44            let known_pairs: Vec<(u32, usize)> = Vec::new();
45            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
46        }
47        n
48    }
49}
50impl Decode<'_> for GetTelemetrySubscriptionsRequest {
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 {
54                api_key: API_KEY,
55                version,
56            });
57        }
58        let flex = is_flexible(version);
59        let mut out = Self::default();
60        if version >= 0 {
61            out.client_instance_id = crate::primitives::uuid::get_uuid(buf)?;
62        }
63        if flex {
64            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
65        }
66        Ok(out)
67    }
68}
69#[cfg(test)]
70impl GetTelemetrySubscriptionsRequest {
71    #[must_use]
72    pub fn populated(version: i16) -> Self {
73        let mut m = Self::default();
74        if version >= 0 {
75            m.client_instance_id = crate::primitives::uuid::Uuid([1u8; 16]);
76        }
77        m
78    }
79}
80/// Default JSON payload matching `Self::default()` for JVM oracle differential testing.
81/// Only includes fields valid for the given version.
82#[must_use]
83#[allow(unused_comparisons)]
84pub fn default_json(version: i16) -> ::serde_json::Value {
85    let mut obj = ::serde_json::Map::new();
86    obj.insert(
87        "clientInstanceId".to_string(),
88        ::serde_json::Value::String("AAAAAAAAAAAAAAAAAAAAAA".to_string()),
89    );
90    ::serde_json::Value::Object(obj)
91}
92impl crate::ProtocolRequest for GetTelemetrySubscriptionsRequest {
93    const API_KEY: i16 = API_KEY;
94    const MIN_VERSION: i16 = MIN_VERSION;
95    const MAX_VERSION: i16 = MAX_VERSION;
96    const FLEXIBLE_MIN: i16 = FLEXIBLE_MIN;
97    type Response = super::get_telemetry_subscriptions_response::GetTelemetrySubscriptionsResponse;
98}