Crates.io | mllp-rs |
lib.rs | mllp-rs |
version | 0.1.1 |
source | src |
created_at | 2022-08-12 09:43:09.081627 |
updated_at | 2022-08-12 12:15:53.645064 |
description | Simple MLLP (Minimal Lower Layer Protocol) implementation. |
homepage | |
repository | https://github.com/Poulpy/mllp-rs |
max_upload_size | |
id | 643898 |
size | 8,902 |
mllp-rs is an MLLP implementation in Rust, for the HL7 file standard. It encapsulates the HL7 file in network transmissions. The library provide utilities for encoding and decoding an encapsulated HL7 file. It also provides helpers to generate MLLP ACK and MLLP NAK.
Put this in your Cargo.toml under [dependencies]
:
mllp-rs = "0.1.0"
To encode an HL7 file use MllpCodec::encode()
, to decode use MllpCodec::decode()
.
Client side code might look like this:
use std::io::prelude::*;
use std::net::TcpStream;
use mllp_rs::MllpCodec;
// Client side
let mut stream = TcpStream::connect("127.0.0.1:5000")?;
let _ = stream.write(MllpCodec::encode("MSH|^~\&|WIR|||36|20200514123930||VXU^V04^VXU_V04|43|P|2.5.1|||ER").as_bytes());
Server side code might look like this:
use std::io::prelude::*;
use std::net::TcpListener;
use mllp_rs::MllpCodec;
let mut listener = TcpListener::bind(addr).unwrap();
for stream in listener.incoming() {
let mut buf: Vec<u8> = vec![];
let _ = stream?.read_to_end(&mut buf);
let decoded_data = String::from_utf8_lossy(MllpCodec::decode(buf.as_slice())?);
}
You might want to check out also hl7-mllp-codec !