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