1use etptypes::energistics::etp::v12::datatypes::object::active_status_kind::ActiveStatusKind;
4use etptypes::energistics::etp::v12::datatypes::object::data_object::DataObject;
5use etptypes::energistics::etp::v12::datatypes::object::resource::Resource;
6use etptypes::energistics::etp::v12::protocol::core::ping::Ping;
7use etptypes::energistics::etp::v12::protocol::store::get_data_objects_response::GetDataObjectsResponse;
8use serde_json;
9use std::collections::HashMap;
10use std::env;
11use std::time::SystemTime;
12
13use etptypes::energistics::etp::v12::datatypes::endpoint_capability_kind::EndpointCapabilityKind;
14use etptypes::energistics::etp::v12::datatypes::protocol::Protocol;
15use etptypes::energistics::etp::v12::datatypes::supported_protocol::SupportedProtocol;
16use etptypes::energistics::etp::v12::datatypes::uuid::random_uuid;
17use etptypes::energistics::etp::v12::protocol::core::request_session::RequestSession;
18use etptypes::error::*;
19use etptypes::helpers::*;
20
21fn main() {
22 env::set_var("RUST_BACKTRACE", "full");
23
24 tests();
25 test_gdor();
26}
27
28fn test_gdor() {
29 let get_dor = GetDataObjectsResponse{
30 data_objects: HashMap::from([
31 ("0".to_string(),
32 DataObject::default_with_params(
33 Resource::default_with_params(
34 "eml:///dataspace('random')/resqml22.TriangulatedSetRepresentation(d0102df3-93f0-4d0b-abbd-63cc7336bb5b)".to_string(),
35 Some(0),Some(0),0,0,0, ActiveStatusKind::Active
36 ),
37 Some(random_uuid()),
38 b"coucou mon contenu".to_vec()
39 )
40 )]
41 ),
42 };
43 let record_a = get_dor.avro_serialize();
44 println!("{:?}", &record_a);
45 let binding = record_a.unwrap();
46 let mut record_slice = binding.as_slice();
47 let result = GetDataObjectsResponse::avro_deserialize(&mut record_slice);
48 println!("{:?}", result);
49}
50
51fn tests() {
52 let protocols = vec![
53 SupportedProtocol {
54 protocol: Protocol::Core as i32,
55 protocol_version: ETP12VERSION,
56 role: "Server".to_string(),
57 protocol_capabilities: HashMap::new(),
58 },
59 SupportedProtocol {
60 protocol: 3,
61 protocol_version: ETP12VERSION,
62 role: "Server".to_string(),
63 protocol_capabilities: HashMap::new(),
64 },
65 SupportedProtocol {
66 protocol: 4,
67 protocol_version: ETP12VERSION,
68 role: "Server".to_string(),
69 protocol_capabilities: HashMap::new(),
70 },
71 ];
72
73 let now = SystemTime::now();
74
75 let rq = RequestSession {
76 application_name: "etp-rs Client Library Application".to_string(),
77 application_version: "0.1".to_string(),
78 client_instance_id: random_uuid(),
79 requested_protocols: protocols,
80 supported_data_objects: vec![],
81 supported_compression: vec!["gzip".to_string()],
82 supported_formats: vec!["xml".to_string(), "json".to_string()],
83 current_date_time: time_to_etp(now),
84 earliest_retained_change_time: time_to_etp(now),
85 server_authorization_required: false,
86 endpoint_capabilities: HashMap::new(),
87 };
88
89 let ping = Ping {
90 current_date_time: time_to_etp(now),
91 };
92
93 for s in EndpointCapabilityKind::iter() {
94 println!("> {:?}", s);
95 }
96
97 println!("{:?}", rq);
98 println!("{:?}", einvalid_messagetype());
99 println!("{:?}", Protocol::Core);
100 println!(
101 "{:?}",
102 serde_json::from_str::<EndpointCapabilityKind>(r#""MaxWebSocketMessagePayloadSize""#)
103 .unwrap()
104 );
105 println!(
106 "{:?}",
107 serde_json::to_string_pretty(&EndpointCapabilityKind::ActiveTimeoutPeriod).unwrap()
108 );
109
110 let record_a = ping.avro_serialize();
112 match record_a {
113 Err(ref e) => println!("{}", e),
114 _ => {}
115 }
116 let record = record_a.unwrap();
117 let mut record_slice = record.as_slice();
118 println!("{:?}", record_slice);
119 println!("{:?}", Ping::avro_deserialize(&mut record_slice));
120
121 println!("{:?}", RequestSession::default());
126
127 let record_a = rq.avro_serialize();
128 match record_a {
129 Err(ref e) => println!("{}", e),
130 _ => {}
131 }
132 let record = record_a.unwrap();
133 let mut record_slice = record.as_slice();
134 println!("{:?}", record_slice);
135 println!("{:?}", RequestSession::avro_deserialize(&mut record_slice));
136 println!("{:?}", rq.as_protocol_message().avro_schema());
137 println!("{:?}", rq.as_protocol_message().avro_serialize());
138}