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