A bitfield where you can't see the insides
This is an implementation of a bitfield in JavaScript, for Node.JS. It's designed for minimal implementation leakage so that I can implement any kind of optimisations I like without breaking any consuming packages.
Right now the implementation is quite naiive, but I hope to improve it as time goes on.
var Bitfield = require("opaque-bitfield");
var bf = new Bitfield();
bf.set(0, true);
console.log(bf.get(0));
Bitfield.get(n);
var a = bf.get(0);
Arguments
- n - the index of the value you want to get
Return Value
boolean value
Bitfield.set(n, v);
bf.set(0, true);
// field 0 is now true
Arguments
- n - the index of the value you want to set
- v - a boolean value
Return Value
Bitfield self
Bitfield.toBuffer(options);
var buf = bf.toBuffer();
// buf is a binary representation of the bitfield's content
Arguments
- options - an object specifying options (so far unused)
Return Value
Buffer content
3-clause BSD. A copy is included with the source.
- GitHub (deoxxa)
- Twitter (@deoxxa)
- Email (deoxxa@fknsrs.biz)