@holo-host/data-translator
v0.1.1
Published
A tool for translating payloads across Holo services (layer 6 of OSI Model)
Downloads
20
Keywords
Readme
Holo Data Translator
A tool for translating payloads across Holo services.
Overview
The main feature of this tool is packing or unpacking messages.
Usage
Server-side
const { Package } = require("@holo-host/data-translator");
...
// Create a normal package
ws.on("message", (msg) => {
let pack = new Package( "Super normal payload..." );
ws.send( pack.toString() );
});
// Create an error package
ws.on("message", (msg) => {
let pack;
try {
...something breaks
} catch ( err ) {
pack = Package.createFromError( "HoloError", err ) );
}
ws.send( pack.toString() );
});
Client-side
const hhdt = require("@holo-host/data-translator");
...
ws.on("message", (msg) => {
const pack = hhdt.parse( msg );
const payload = pack.value();
// Normal package
console.log( payload ); // "Super normal payload..."
// Error package
console.log( payload instanceof Error ); // true
});
API Reference
See API.md
Contributing
See CONTRIBUTING.md