Skip to content

pranavrajs/bufftoobj

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

buffToObj

A small library that helps to create user defined objects from a buffer.

Usage

var buffToObj = require('bufftoobj');

// eg: model = {'ip' => ipv4, num1 => ulong}
var modelArray = [{
	"attrName" : 'ipAddr',
	"type": 'ipv4',
	"length" : 4
}, {
	"attrName" : 'num1',
	"type" : 'uInt32',
	"length" : 4
}];

var object = buffToObj(new Buffer([192, 168, 0, 183,255, 255, 0, 0]), 0, modelArray);
console.log(object); // {'ip' : '192.168.0.183', 'num1' : 65536}

Supported types

ipv4, uInt32, uInt16, Int16, char string

For string, you need to give the the encType attribute also. encType can be ascii,utf8.

Testing

npm test to run mocha tests using mocha runner

License

This project is licensed under the MIT license.

About

A small library that helps to create user defined objects from a buffer.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published