crabka_protocol/opt/rustwide/workdir/generated/
GetTelemetrySubscriptionsResponse.owned.rs1use bytes::{Buf, BufMut};
4
5use crate::primitives::fixed::{get_bool, get_i16, get_i32, get_i8, put_bool, put_i16, put_i32, put_i8};
6use crate::primitives::string_bytes::{
7 compact_string_len, get_compact_string_owned, get_string_owned,
8 put_compact_string, put_string, string_len,
9};
10use crate::tagged_fields::{read_tagged_fields, tagged_fields_len, WriteTaggedFields};
11use crate::{Decode, Encode, ProtocolError, UnknownTaggedFields};
12
13pub const API_KEY: i16 = 71;
14pub const MIN_VERSION: i16 = 0;
15pub const MAX_VERSION: i16 = 0;
16pub const FLEXIBLE_MIN: i16 = 0;
17
18#[inline]
19fn is_flexible(version: i16) -> bool { version >= FLEXIBLE_MIN }
20
21#[derive(Debug, Clone, PartialEq, Eq, Default)]
22pub struct GetTelemetrySubscriptionsResponse {
23 pub throttle_time_ms: i32,
24 pub error_code: i16,
25 pub client_instance_id: crate::primitives::uuid::Uuid,
26 pub subscription_id: i32,
27 pub accepted_compression_types: Vec<i8>,
28 pub push_interval_ms: i32,
29 pub telemetry_max_bytes: i32,
30 pub delta_temporality: bool,
31 pub requested_metrics: Vec<String>,
32 pub unknown_tagged_fields: UnknownTaggedFields,
33}
34
35impl Encode for GetTelemetrySubscriptionsResponse {
36 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
37 if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
38 return Err(ProtocolError::UnsupportedVersion { api_key: API_KEY, version });
39 }
40 let flex = is_flexible(version);
41 if version >= 0 { put_i32(buf, self.throttle_time_ms) }
42 if version >= 0 { put_i16(buf, self.error_code) }
43 if version >= 0 { crate::primitives::uuid::put_uuid(buf, self.client_instance_id) }
44 if version >= 0 { put_i32(buf, self.subscription_id) }
45 if version >= 0 { { crate::primitives::array::put_array_len(buf, (self.accepted_compression_types).len(), flex); for it in &self.accepted_compression_types { put_i8(buf, *it); } } }
46 if version >= 0 { put_i32(buf, self.push_interval_ms) }
47 if version >= 0 { put_i32(buf, self.telemetry_max_bytes) }
48 if version >= 0 { put_bool(buf, self.delta_temporality) }
49 if version >= 0 { { crate::primitives::array::put_array_len(buf, (self.requested_metrics).len(), flex); for it in &self.requested_metrics { if flex { put_compact_string(buf, &*it) } else { put_string(buf, &*it) }; } } }
50 if flex {
51 let tagged = WriteTaggedFields::new();
52 tagged.write(buf, &self.unknown_tagged_fields);
53 }
54 Ok(())
55 }
56 fn encoded_len(&self, version: i16) -> usize {
57 let flex = is_flexible(version);
58 let mut n: usize = 0;
59 if version >= 0 { n += 4; }
60 if version >= 0 { n += 2; }
61 if version >= 0 { n += 16; }
62 if version >= 0 { n += 4; }
63 if version >= 0 { n += { let prefix = crate::primitives::array::array_len_prefix_len((self.accepted_compression_types).len(), flex); let body: usize = (self.accepted_compression_types).iter().map(|_| 1).sum(); prefix + body }; }
64 if version >= 0 { n += 4; }
65 if version >= 0 { n += 4; }
66 if version >= 0 { n += 1; }
67 if version >= 0 { n += { let prefix = crate::primitives::array::array_len_prefix_len((self.requested_metrics).len(), flex); let body: usize = (self.requested_metrics).iter().map(|it| if flex { compact_string_len(&*it) } else { string_len(&*it) }).sum(); prefix + body }; }
68 if flex {
69 let known_pairs: Vec<(u32, usize)> = Vec::new();
70 n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
71 }
72 n
73 }
74}
75
76impl<'de> Decode<'de> for GetTelemetrySubscriptionsResponse {
77 fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
78 if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
79 return Err(ProtocolError::UnsupportedVersion { api_key: API_KEY, version });
80 }
81 let flex = is_flexible(version);
82 let mut out = Self::default();
83 if version >= 0 { out.throttle_time_ms = get_i32(buf)?; }
84 if version >= 0 { out.error_code = get_i16(buf)?; }
85 if version >= 0 { out.client_instance_id = crate::primitives::uuid::get_uuid(buf)?; }
86 if version >= 0 { out.subscription_id = get_i32(buf)?; }
87 if version >= 0 { out.accepted_compression_types = { let n = crate::primitives::array::get_array_len(buf, flex)?; let mut v = Vec::with_capacity(n); for _ in 0..n { v.push(get_i8(buf)?); } v }; }
88 if version >= 0 { out.push_interval_ms = get_i32(buf)?; }
89 if version >= 0 { out.telemetry_max_bytes = get_i32(buf)?; }
90 if version >= 0 { out.delta_temporality = get_bool(buf)?; }
91 if version >= 0 { out.requested_metrics = { let n = crate::primitives::array::get_array_len(buf, flex)?; let mut v = Vec::with_capacity(n); for _ in 0..n { v.push(if flex { get_compact_string_owned(buf)? } else { get_string_owned(buf)? }); } v }; }
92 if flex {
93 out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| {
94 Ok(false)
95 })?;
96 }
97 Ok(out)
98 }
99}
100
101#[must_use]
104#[allow(unused_comparisons)]
105pub fn default_json(version: i16) -> ::serde_json::Value {
106 let mut obj = ::serde_json::Map::new();
107 obj.insert("throttleTimeMs".to_string(), ::serde_json::json!(0));
108 obj.insert("errorCode".to_string(), ::serde_json::json!(0));
109 obj.insert("clientInstanceId".to_string(), ::serde_json::Value::String("AAAAAAAAAAAAAAAAAAAAAA".to_string()));
110 obj.insert("subscriptionId".to_string(), ::serde_json::json!(0));
111 obj.insert("acceptedCompressionTypes".to_string(), ::serde_json::Value::Array(vec![]));
112 obj.insert("pushIntervalMs".to_string(), ::serde_json::json!(0));
113 obj.insert("telemetryMaxBytes".to_string(), ::serde_json::json!(0));
114 obj.insert("deltaTemporality".to_string(), ::serde_json::Value::Bool(false));
115 obj.insert("requestedMetrics".to_string(), ::serde_json::Value::Array(vec![]));
116 ::serde_json::Value::Object(obj)
117}