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_i32, get_i8, put_bool, put_i32, put_i8};
6use crate::primitives::string_bytes::{bytes_len, compact_bytes_len, get_bytes_owned, get_compact_bytes_owned, put_bytes, put_compact_bytes};
7use crate::tagged_fields::{read_tagged_fields, tagged_fields_len, WriteTaggedFields};
8use crate::{Decode, Encode, ProtocolError, UnknownTaggedFields};
9
10pub const API_KEY: i16 = 72;
11pub const MIN_VERSION: i16 = 0;
12pub const MAX_VERSION: i16 = 0;
13pub const FLEXIBLE_MIN: i16 = 0;
14
15#[inline]
16fn is_flexible(version: i16) -> bool { version >= FLEXIBLE_MIN }
17
18#[derive(Debug, Clone, PartialEq, Eq, Default)]
19pub struct PushTelemetryRequest {
20    pub client_instance_id: crate::primitives::uuid::Uuid,
21    pub subscription_id: i32,
22    pub terminating: bool,
23    pub compression_type: i8,
24    pub metrics: ::bytes::Bytes,
25    pub unknown_tagged_fields: UnknownTaggedFields,
26}
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 { api_key: API_KEY, version });
32        }
33        let flex = is_flexible(version);
34        if version >= 0 { crate::primitives::uuid::put_uuid(buf, self.client_instance_id) }
35        if version >= 0 { put_i32(buf, self.subscription_id) }
36        if version >= 0 { put_bool(buf, self.terminating) }
37        if version >= 0 { put_i8(buf, self.compression_type) }
38        if version >= 0 { if flex { put_compact_bytes(buf, &self.metrics) } else { put_bytes(buf, &self.metrics) } }
39        if flex {
40            let tagged = WriteTaggedFields::new();
41            tagged.write(buf, &self.unknown_tagged_fields);
42        }
43        Ok(())
44    }
45    fn encoded_len(&self, version: i16) -> usize {
46        let flex = is_flexible(version);
47        let mut n: usize = 0;
48        if version >= 0 { n += 16; }
49        if version >= 0 { n += 4; }
50        if version >= 0 { n += 1; }
51        if version >= 0 { n += 1; }
52        if version >= 0 { n += if flex { compact_bytes_len(&self.metrics) } else { bytes_len(&self.metrics) }; }
53        if flex {
54            let known_pairs: Vec<(u32, usize)> = Vec::new();
55            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
56        }
57        n
58    }
59}
60
61impl<'de> Decode<'de> for PushTelemetryRequest {
62    fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
63        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
64            return Err(ProtocolError::UnsupportedVersion { api_key: API_KEY, version });
65        }
66        let flex = is_flexible(version);
67        let mut out = Self::default();
68        if version >= 0 { out.client_instance_id = crate::primitives::uuid::get_uuid(buf)?; }
69        if version >= 0 { out.subscription_id = get_i32(buf)?; }
70        if version >= 0 { out.terminating = get_bool(buf)?; }
71        if version >= 0 { out.compression_type = get_i8(buf)?; }
72        if version >= 0 { out.metrics = if flex { get_compact_bytes_owned(buf)? } else { get_bytes_owned(buf)? }; }
73        if flex {
74            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| {
75                Ok(false)
76            })?;
77        }
78        Ok(out)
79    }
80}
81
82/// Default JSON payload matching `Self::default()` for JVM oracle differential testing.
83/// Only includes fields valid for the given version.
84#[must_use]
85#[allow(unused_comparisons)]
86pub fn default_json(version: i16) -> ::serde_json::Value {
87    let mut obj = ::serde_json::Map::new();
88    obj.insert("clientInstanceId".to_string(), ::serde_json::Value::String("AAAAAAAAAAAAAAAAAAAAAA".to_string()));
89    obj.insert("subscriptionId".to_string(), ::serde_json::json!(0));
90    obj.insert("terminating".to_string(), ::serde_json::Value::Bool(false));
91    obj.insert("compressionType".to_string(), ::serde_json::json!(0));
92    obj.insert("metrics".to_string(), ::serde_json::Value::String(String::new()));
93    ::serde_json::Value::Object(obj)
94}
95
96impl crate::ProtocolRequest for PushTelemetryRequest {
97    const API_KEY: i16 = API_KEY;
98    const MIN_VERSION: i16 = MIN_VERSION;
99    const MAX_VERSION: i16 = MAX_VERSION;
100    const FLEXIBLE_MIN: i16 = FLEXIBLE_MIN;
101    type Response = super::push_telemetry_response::PushTelemetryResponse;
102}