etptypes/energistics/etp/v12/protocol/supported_types/
get_supported_types.rs

1// SPDX-FileCopyrightText: 2023 Geosiris
2// SPDX-License-Identifier: Apache-2.0 OR MIT
3#![allow(unused_imports)]
4#![allow(non_camel_case_types)]
5use crate::helpers::*;
6use apache_avro::{Error, Schema};
7use bytes;
8use derivative::Derivative;
9use std::collections::HashMap;
10use std::time::SystemTime;
11
12use crate::energistics::etp::v12::datatypes::object::context_scope_kind::ContextScopeKind;
13use crate::helpers::ETPMetadata;
14use crate::helpers::Schemable;
15use crate::protocols::ProtocolMessage;
16use apache_avro::{from_avro_datum, from_value, AvroResult};
17use std::io::Read;
18
19#[derive(Debug, PartialEq, Clone, serde::Deserialize, serde::Serialize, Derivative)]
20#[serde(rename_all = "PascalCase")]
21pub struct GetSupportedTypes {
22    #[serde(rename = "uri")]
23    pub uri: String,
24
25    #[serde(rename = "scope")]
26    pub scope: ContextScopeKind,
27
28    #[serde(rename = "returnEmptyTypes")]
29    #[derivative(Default(value = "false"))]
30    pub return_empty_types: bool,
31
32    #[serde(rename = "countObjects")]
33    #[derivative(Default(value = "false"))]
34    pub count_objects: bool,
35}
36
37fn getsupportedtypes_avro_schema() -> Option<Schema> {
38    match Schema::parse_str(AVRO_SCHEMA) {
39        Ok(result) => Some(result),
40        Err(e) => {
41            panic!("{:?}", e);
42        }
43    }
44}
45
46impl Schemable for GetSupportedTypes {
47    fn avro_schema(&self) -> Option<Schema> {
48        getsupportedtypes_avro_schema()
49    }
50    fn avro_schema_str(&self) -> &'static str {
51        AVRO_SCHEMA
52    }
53}
54
55impl AvroSerializable for GetSupportedTypes {}
56
57impl AvroDeserializable for GetSupportedTypes {
58    fn avro_deserialize<R: Read>(input: &mut R) -> AvroResult<GetSupportedTypes> {
59        let record =
60            from_avro_datum(&getsupportedtypes_avro_schema().unwrap(), input, None).unwrap();
61        from_value::<GetSupportedTypes>(&record)
62    }
63}
64
65impl ETPMetadata for GetSupportedTypes {
66    fn protocol(&self) -> i32 {
67        25
68    }
69    fn message_type(&self) -> i32 {
70        1
71    }
72    fn sender_role(&self) -> Vec<Role> {
73        vec![Role::Customer]
74    }
75    fn protocol_roles(&self) -> Vec<Role> {
76        vec![Role::Store, Role::Customer]
77    }
78    fn multipart_flag(&self) -> bool {
79        false
80    }
81}
82
83impl GetSupportedTypes {
84    pub fn as_protocol_message(&self) -> ProtocolMessage {
85        ProtocolMessage::SupportedTypes_GetSupportedTypes(self.clone())
86    }
87}
88
89impl GetSupportedTypes {
90    /* Protocol 25, MessageType : 1 */
91    pub fn default_with_params(uri: String, scope: ContextScopeKind) -> GetSupportedTypes {
92        GetSupportedTypes {
93            uri,
94            scope,
95            return_empty_types: false,
96            count_objects: false,
97        }
98    }
99}
100
101pub static AVRO_SCHEMA: &'static str = r#"{
102    "type": "record",
103    "namespace": "Energistics.Etp.v12.Protocol.SupportedTypes",
104    "name": "GetSupportedTypes",
105    "protocol": "25",
106    "messageType": "1",
107    "senderRole": "customer",
108    "protocolRoles": "store,customer",
109    "multipartFlag": false,
110    "fields": [
111        {
112            "name": "uri",
113            "type": "string"
114        },
115        {
116            "name": "scope",
117            "type": {
118                "type": "enum",
119                "namespace": "Energistics.Etp.v12.Datatypes.Object",
120                "name": "ContextScopeKind",
121                "symbols": [
122                    "self",
123                    "sources",
124                    "targets",
125                    "sourcesOrSelf",
126                    "targetsOrSelf"
127                ],
128                "fullName": "Energistics.Etp.v12.Datatypes.Object.ContextScopeKind",
129                "depends": []
130            }
131        },
132        {
133            "name": "returnEmptyTypes",
134            "type": "boolean",
135            "default": false
136        },
137        {
138            "name": "countObjects",
139            "type": "boolean",
140            "default": false
141        }
142    ],
143    "fullName": "Energistics.Etp.v12.Protocol.SupportedTypes.GetSupportedTypes",
144    "depends": [
145        "Energistics.Etp.v12.Datatypes.Object.ContextScopeKind"
146    ]
147}"#;