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