Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/pranavrajs/bufftoobj
A small library that helps to create user defined objects from a buffer.
https://github.com/pranavrajs/bufftoobj
Last synced: about 1 month ago
JSON representation
A small library that helps to create user defined objects from a buffer.
- Host: GitHub
- URL: https://github.com/pranavrajs/bufftoobj
- Owner: pranavrajs
- License: mit
- Created: 2015-11-05T11:39:49.000Z (about 9 years ago)
- Default Branch: master
- Last Pushed: 2016-02-21T18:16:01.000Z (over 8 years ago)
- Last Synced: 2024-09-14T10:02:22.553Z (2 months ago)
- Language: JavaScript
- Homepage: https://www.npmjs.com/package/bufftoobj
- Size: 3.91 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# buffToObj
A small library that helps to create user defined objects from a buffer.## Usage
```javascript
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.