Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/timgabets/dhi-xml
A library for TSYS DHI (Device Host Interface) XML messages serialization/deserialization
https://github.com/timgabets/dhi-xml
Last synced: about 2 months ago
JSON representation
A library for TSYS DHI (Device Host Interface) XML messages serialization/deserialization
- Host: GitHub
- URL: https://github.com/timgabets/dhi-xml
- Owner: timgabets
- License: mit
- Created: 2020-06-01T20:03:04.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2020-07-06T16:42:34.000Z (over 4 years ago)
- Last Synced: 2024-11-14T15:18:52.335Z (about 2 months ago)
- Language: Rust
- Size: 21.5 KB
- Stars: 1
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
## DHI XML
![License: MIT](https://img.shields.io/crates/l/dhi-xml)
[![Build Status](https://travis-ci.org/timgabets/dhi-xml.svg?branch=master)](https://travis-ci.org/timgabets/dhi-xml)
[![Crates.io](https://img.shields.io/crates/v/dhi_xml.svg)](https://crates.io/crates/dhi-xml)Rust community library for serializaing/deserializing TSYS DHI (Device Host Interface) XML messages.
### Usage
```rust
use dhi_xml::{DHIRequest, DHIResponse};
```DHI requests:
```rust
// JSON payload (for example, from HTTP request)
let iso_data = r#"{
"i000": "0100",
"i002": "555544******0895",
"i007": "Transmission date & time ",
"i011": "STAN",
"i012": "hhmmss",
"i013": "MMDD",
"i037": "Retrieval Reference Number"
}"#;// Deserializing request from the given JSON payload
let r: DHIRequest = DHIRequest::new(serde_json::from_str(&iso_data).unwrap());// The data may now be accessed with
assert_eq!(r.iso_fields["i002"], "555544******0895");// Serialization
let msg = r.serialize().unwrap();// The message may be sent through the TCP stream
let s = TcpStream::connect(host);
s.write_all(&msg.as_bytes());
```DHI response:
```rustlet s = r##"
0
OK
0110555544******09613000000000000000002804114717"
"##;// Deserialization from the XML payload
let resp: DHIResponse = from_reader(s.as_bytes()).unwrap();// Accessing data
assert_eq!(resp.res.code, 0);
assert_eq!(resp.res.description, "OK");
assert_eq!(resp.iso_fields["i000"], "0110");
assert_eq!(resp.iso_fields["i002"], "555544******0961");// Serializing response to JSON
let msg = resp.serialize().unwrap();// Sending as payload in HTTP response
Ok(HttpResponse::Ok()
.content_type("application/json")
.header("X-Hdr", "sample")
.body(msg)),
```