@endeo/specials

Build "object spec" for compact object encoding.
A flexible specification allowing progressive improvements for greater performance.
Features:
- knows a list of property names for an object to allow encoding without them which avoids all those bytes.
- optionally knows defaults to avoid encoding those values.
- optionally knows type to avoid the value's type check every time for faster encoding and decoding.
- optionally uses special keys to trigger automatic encoding/decoding changes for compression (or any reason). You may define your own special keys and how they are used.
See packages:
- endeo
- enbyte
- debyte
- unstring
Install
npm install --save @endeo/specials
Usage
var build = require('@endeo/specials')
var types = require('@endeo/types')
var specials = build({ types: types })
specials.addType('someId', {
encode: function(enbyte, value, output) {},
decode: function(debyte, input) {}
})
specials.addType('fruit', {
select: [ 'apple', 'banana', 'orange' ]
})
function createThing() {
return {
key1: 'someDefault',
key2: 2,
fruit: 'banana'
}
}
var enhancers = {
key1: 'name of a type',
key2: {
type: 'name of a type',
encode: function(enbyte, value, output) {},
decode: function(debyte, input) {}
},
fruit: 'fruit'
}
var spec = specials.build(1, createThing, enhancers)
function SomeClass() {}
spec.imprint(SomeClass.prototype)
var someObject = {}
spec.imprint(someObject)