Skip to content

BML(binary markup language) is a powerful declarative and symmetrical parser and packer for binary data.

License

Notifications You must be signed in to change notification settings

srg-kostyrko/BML

Repository files navigation

Logo of the project

NpmLicense npm

BML

Binary markup language

BML a powerful declarative and symmetrical parser and packer for binary data.

Instead of writing imperative code to parse a piece of data, you declaratively define a data structure that describes your data. And you can use it in one direction to parse data into Javascript objects, and in the other direction, to pack objects into binary data.

Installing / Getting started

NodeJS: Just use npm to install BML and you are set :)

npm install binary-markup --save
yarn add binary-markup

Example

First describe structure of binary data

const { byte, struct } = require('binary-markup');

// define composite type
const rgb = struct(byte`r`, byte`g`, byte`b`);
// you can use previously defined type to describe more complex ones
const colorsType = struct(rgb`main`, rgb`secondary`);

Now you can read and parse binary data

const fs = require('fs');
const { parse } = require('binary-markup');

fs.readFile('file.bin', function(err, data) {
  console.log(parse(colorsType, data));
});

You can as well convert javascript object to binary data

const { pack } = require('binary-markup');

console.log(
  pack(colorsType, {
    main: {
      r: 211,
      g: 33,
      b: 22,
    },
    secondary: {
      r: 255,
      g: 255,
      b: 255,
    },
  })
);

Features

TBD

Contributing

If you'd like to contribute, please fork the repository and use a feature branch. Pull requests are warmly welcome.

Links

Licensing

The code in this project is licensed under MIT license.

About

BML(binary markup language) is a powerful declarative and symmetrical parser and packer for binary data.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 3

  •  
  •  
  •