Skip to main content

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