Skip to main content

crabka_protocol/opt/rustwide/workdir/generated/
PushTelemetryRequest.owned.rs

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