Skip to content

deoxxa/opaque-bitfield

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 

Repository files navigation

opaque-bitfield

A bitfield where you can't see the insides

Overview

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.

Usage

var Bitfield = require("opaque-bitfield");

var bf = new Bitfield();

bf.set(0, true);

console.log(bf.get(0));

API

get

Bitfield.get(n);
var a = bf.get(0);

Arguments

  • n - the index of the value you want to get

Return Value

boolean value

set

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

toBuffer

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

License

3-clause BSD. A copy is included with the source.

Contact

About

A bitfield where you can't see the insides

Resources

License

Stars

Watchers

Forks

Packages

No packages published