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