Giter Site home page Giter Site logo

hub-data-parser's Introduction

hub-data-parser

Quick library to parse bytes continuously from a Nodejs buffer into float, integers, etc

To use this library, just create the object from the buffer. Then, extract the data you are expecting using the provided functions.

Note: All variables are supposed to be stored in Little-Endian in the buffer

Examples

Let's put inside a buffer a date & time, with year (2 bytes), month (1), day (1), hours (1), minutes (1), seconds (1). Let's add as well a 16 bits integer and a single 8 bit value.

// Get the library
var HubDataParser = require('./hub-data-parser');

// Create a buffer with:
//
// datetime:
// 07 E1 = 2017
// 08 = August
// 15 = 15th
// 14 11 10 = 14:11:10
//
// integer:
// 10 1 = 0x0A01 = 2561
//
// char:
// 5
const buf = Buffer.from([
  0xE1, 0x07,
  8, 
  15, 
  14, 11, 10,
  1, 10, 
  5
]);

var p1 = new HubDataParser(buf);

console.log(p1.getDate());
console.log(p1.getInteger());
console.log(p1.getByte());

And the console log should be what we are expecting...

2017-08-15T14:11:10.000Z
2561
5

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.