krabka_protocol/opt/rustwide/workdir/generated/
PushTelemetryRequest.owned.rs1use bytes::{Buf, BufMut};
4
5use crate::{
6 Decode, Encode, ProtocolError, UnknownTaggedFields,
7 primitives::{
8 fixed::{get_bool, get_i8, get_i32, put_bool, put_i8, put_i32},
9 string_bytes::{
10 bytes_len, compact_bytes_len, get_bytes_owned, get_compact_bytes_owned, put_bytes,
11 put_compact_bytes,
12 },
13 },
14 tagged_fields::{WriteTaggedFields, read_tagged_fields, tagged_fields_len},
15};
16pub const API_KEY: i16 = 72;
17pub const MIN_VERSION: i16 = 0;
18pub const MAX_VERSION: i16 = 0;
19pub const LATEST_STABLE_VERSION: i16 = 0;
20pub const FLEXIBLE_MIN: i16 = 0;
21#[inline]
22#[must_use]
23pub fn is_flexible(version: i16) -> bool {
24 version >= FLEXIBLE_MIN
25}
26#[derive(Debug, Clone, PartialEq, Eq, Default)]
27pub struct PushTelemetryRequest {
28 pub client_instance_id: crate::primitives::uuid::Uuid,
29 pub subscription_id: i32,
30 pub terminating: bool,
31 pub compression_type: i8,
32 pub metrics: ::bytes::Bytes,
33 pub unknown_tagged_fields: UnknownTaggedFields,
34}
35impl Encode for PushTelemetryRequest {
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 {
39 api_key: API_KEY,
40 version,
41 });
42 }
43 let flex = is_flexible(version);
44 if version >= 0 {
45 crate::primitives::uuid::put_uuid(buf, self.client_instance_id);
46 }
47 if version >= 0 {
48 put_i32(buf, self.subscription_id);
49 }
50 if version >= 0 {
51 put_bool(buf, self.terminating);
52 }
53 if version >= 0 {
54 put_i8(buf, self.compression_type);
55 }
56 if version >= 0 {
57 if flex {
58 let () = put_compact_bytes(buf, &self.metrics);
59 } else {
60 let () = put_bytes(buf, &self.metrics);
61 }
62 }
63 if flex {
64 let tagged = WriteTaggedFields::new();
65 tagged.write(buf, &self.unknown_tagged_fields);
66 }
67 Ok(())
68 }
69 fn encoded_len(&self, version: i16) -> usize {
70 let flex = is_flexible(version);
71 let mut n: usize = 0;
72 if version >= 0 {
73 n += 16;
74 }
75 if version >= 0 {
76 n += 4;
77 }
78 if version >= 0 {
79 n += 1;
80 }
81 if version >= 0 {
82 n += 1;
83 }
84 if version >= 0 {
85 n += if flex {
86 compact_bytes_len(&self.metrics)
87 } else {
88 bytes_len(&self.metrics)
89 };
90 }
91 if flex {
92 let known_pairs: Vec<(u32, usize)> = Vec::new();
93 n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
94 }
95 n
96 }
97}
98impl Decode<'_> for PushTelemetryRequest {
99 fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
100 if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
101 return Err(ProtocolError::UnsupportedVersion {
102 api_key: API_KEY,
103 version,
104 });
105 }
106 let flex = is_flexible(version);
107 let mut out = Self::default();
108 if version >= 0 {
109 out.client_instance_id = crate::primitives::uuid::get_uuid(buf)?;
110 }
111 if version >= 0 {
112 out.subscription_id = get_i32(buf)?;
113 }
114 if version >= 0 {
115 out.terminating = get_bool(buf)?;
116 }
117 if version >= 0 {
118 out.compression_type = get_i8(buf)?;
119 }
120 if version >= 0 {
121 out.metrics = if flex {
122 get_compact_bytes_owned(buf)?
123 } else {
124 get_bytes_owned(buf)?
125 };
126 }
127 if flex {
128 out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
129 }
130 Ok(out)
131 }
132}
133#[cfg(test)]
134impl PushTelemetryRequest {
135 #[must_use]
136 pub fn populated(version: i16) -> Self {
137 let mut m = Self::default();
138 if version >= 0 {
139 m.client_instance_id = crate::primitives::uuid::Uuid([1u8; 16]);
140 }
141 if version >= 0 {
142 m.subscription_id = 1i32;
143 }
144 if version >= 0 {
145 m.terminating = true;
146 }
147 if version >= 0 {
148 m.compression_type = 1i8;
149 }
150 if version >= 0 {
151 m.metrics = ::bytes::Bytes::from_static(b"x");
152 }
153 m
154 }
155}
156#[must_use]
159#[allow(unused_comparisons)]
160pub fn default_json(_version: i16) -> ::serde_json::Value {
161 let mut obj = ::serde_json::Map::new();
162 obj.insert(
163 "clientInstanceId".to_string(),
164 ::serde_json::Value::String("AAAAAAAAAAAAAAAAAAAAAA".to_string()),
165 );
166 obj.insert("subscriptionId".to_string(), ::serde_json::json!(0));
167 obj.insert("terminating".to_string(), ::serde_json::Value::Bool(false));
168 obj.insert("compressionType".to_string(), ::serde_json::json!(0));
169 obj.insert(
170 "metrics".to_string(),
171 ::serde_json::Value::String(String::new()),
172 );
173 ::serde_json::Value::Object(obj)
174}
175impl crate::ProtocolRequest for PushTelemetryRequest {
176 const API_KEY: i16 = API_KEY;
177 const MIN_VERSION: i16 = MIN_VERSION;
178 const MAX_VERSION: i16 = MAX_VERSION;
179 const LATEST_STABLE_VERSION: i16 = LATEST_STABLE_VERSION;
180 const FLEXIBLE_MIN: i16 = FLEXIBLE_MIN;
181 type Response = super::push_telemetry_response::PushTelemetryResponse;
182}