etptypes/energistics/etp/v12/protocol/core/
pong.rs1#![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::helpers::ETPMetadata;
13use crate::helpers::Schemable;
14use crate::protocols::ProtocolMessage;
15use apache_avro::{from_avro_datum, from_value, AvroResult};
16use std::io::Read;
17#[derive(Debug, PartialEq, Clone, serde::Deserialize, serde::Serialize, Derivative)]
18#[serde(rename_all = "PascalCase")]
19pub struct Pong {
20 #[serde(rename = "currentDateTime")]
21 pub current_date_time: i64,
22}
23
24fn pong_avro_schema() -> Option<Schema> {
25 match Schema::parse_str(AVRO_SCHEMA) {
26 Ok(result) => Some(result),
27 Err(e) => {
28 panic!("{:?}", e);
29 }
30 }
31}
32
33impl Schemable for Pong {
34 fn avro_schema(&self) -> Option<Schema> {
35 pong_avro_schema()
36 }
37 fn avro_schema_str(&self) -> &'static str {
38 AVRO_SCHEMA
39 }
40}
41
42impl AvroSerializable for Pong {}
43
44impl AvroDeserializable for Pong {
45 fn avro_deserialize<R: Read>(input: &mut R) -> AvroResult<Pong> {
46 let record = from_avro_datum(&pong_avro_schema().unwrap(), input, None).unwrap();
47 from_value::<Pong>(&record)
48 }
49}
50
51impl ETPMetadata for Pong {
52 fn protocol(&self) -> i32 {
53 0
54 }
55 fn message_type(&self) -> i32 {
56 9
57 }
58 fn sender_role(&self) -> Vec<Role> {
59 vec![Role::Client, Role::Server]
60 }
61 fn protocol_roles(&self) -> Vec<Role> {
62 vec![Role::Client, Role::Server]
63 }
64 fn multipart_flag(&self) -> bool {
65 false
66 }
67}
68
69impl Pong {
70 pub fn as_protocol_message(&self) -> ProtocolMessage {
71 ProtocolMessage::Core_Pong(self.clone())
72 }
73}
74
75impl Default for Pong {
76 fn default() -> Pong {
78 Pong {
79 current_date_time: time_to_etp(SystemTime::now()),
80 }
81 }
82}
83
84pub static AVRO_SCHEMA: &'static str = r#"{
85 "type": "record",
86 "namespace": "Energistics.Etp.v12.Protocol.Core",
87 "name": "Pong",
88 "protocol": "0",
89 "messageType": "9",
90 "senderRole": "client,server",
91 "protocolRoles": "client, server",
92 "multipartFlag": false,
93 "fields": [
94 {
95 "name": "currentDateTime",
96 "type": "long"
97 }
98 ],
99 "fullName": "Energistics.Etp.v12.Protocol.Core.Pong",
100 "depends": []
101}"#;