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    primitives::uuid::{Uuid, get_uuid, put_uuid},
8    tagged_fields::{WriteTaggedFields, read_tagged_fields, tagged_fields_len},
9};
10pub const API_KEY: i16 = 71;
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 GetTelemetrySubscriptionsRequest {
22    pub client_instance_id: Uuid,
23    pub unknown_tagged_fields: UnknownTaggedFields,
24}
25impl Encode for GetTelemetrySubscriptionsRequest {
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_uuid(buf, self.client_instance_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 += 16;
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 GetTelemetrySubscriptionsRequest {
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.client_instance_id = get_uuid(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 GetTelemetrySubscriptionsRequest {
77    #[must_use]
78    pub fn populated(version: i16) -> Self {
79        let mut m = Self::default();
80        if version >= 0 {
81            m.client_instance_id = Uuid([1u8; 16]);
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(
93        "clientInstanceId".to_owned(),
94        ::serde_json::Value::String("AAAAAAAAAAAAAAAAAAAAAA".to_owned()),
95    );
96    ::serde_json::Value::Object(obj)
97}
98impl crate::ProtocolRequest for GetTelemetrySubscriptionsRequest {
99    const API_KEY: i16 = API_KEY;
100    const MIN_VERSION: i16 = MIN_VERSION;
101    const MAX_VERSION: i16 = MAX_VERSION;
102    const LATEST_STABLE_VERSION: i16 = LATEST_STABLE_VERSION;
103    const FLEXIBLE_MIN: i16 = FLEXIBLE_MIN;
104    type Response = super::get_telemetry_subscriptions_response::GetTelemetrySubscriptionsResponse;
105}