krabka_protocol/opt/rustwide/workdir/generated/
GetTelemetrySubscriptionsRequest.borrowed.rs1use bytes::BufMut;
3
4use crate::{
5 DecodeBorrow, Encode, ProtocolError, UnknownTaggedFields,
6 owned::get_telemetry_subscriptions_request,
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 GetTelemetrySubscriptionsRequest {
26 #[must_use]
27 pub fn to_owned(
28 &self,
29 ) -> get_telemetry_subscriptions_request::GetTelemetrySubscriptionsRequest {
30 get_telemetry_subscriptions_request::GetTelemetrySubscriptionsRequest {
31 client_instance_id: (self.client_instance_id),
32 unknown_tagged_fields: self.unknown_tagged_fields.clone(),
33 }
34 }
35}
36impl Encode for GetTelemetrySubscriptionsRequest {
37 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
38 if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
39 return Err(ProtocolError::UnsupportedVersion {
40 api_key: API_KEY,
41 version,
42 });
43 }
44 let flex = is_flexible(version);
45 if version >= 0 {
46 put_uuid(buf, self.client_instance_id);
47 }
48 if flex {
49 let tagged = WriteTaggedFields::new();
50 tagged.write(buf, &self.unknown_tagged_fields)?;
51 }
52 Ok(())
53 }
54 fn encoded_len(&self, version: i16) -> usize {
55 let flex = is_flexible(version);
56 let mut n: usize = 0;
57 if version >= 0 {
58 n += 16;
59 }
60 if flex {
61 let known_pairs: Vec<(u32, usize)> = Vec::new();
62 n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
63 }
64 n
65 }
66}
67impl<'de> DecodeBorrow<'de> for GetTelemetrySubscriptionsRequest {
68 fn decode_borrow(buf: &mut &'de [u8], version: i16) -> Result<Self, ProtocolError> {
69 if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
70 return Err(ProtocolError::UnsupportedVersion {
71 api_key: API_KEY,
72 version,
73 });
74 }
75 let flex = is_flexible(version);
76 let mut out = Self::default();
77 if version >= 0 {
78 out.client_instance_id = get_uuid(buf)?;
79 }
80 if flex {
81 out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
82 }
83 Ok(out)
84 }
85}
86#[cfg(test)]
87impl GetTelemetrySubscriptionsRequest {
88 #[must_use]
89 pub fn populated(version: i16) -> Self {
90 let mut m = Self::default();
91 if version >= 0 {
92 m.client_instance_id = Uuid([1u8; 16]);
93 }
94 m
95 }
96}