objectstruct
schema based object encoding/decoding using varstruct that supports strings, booleans etc
npm install objectstruct
Usage
var ostruct =var example =var buf = exampleconsole // prints a buffervar parsed = exampleconsole // prints an object similar to above
Encodings
In addition to the encodings supported by varstruct (UInt32BE
etc)
the following encodings/aliases are supported as well
string
boolean
bytes
(orbuffer
)number
(ordouble
orDoubleBE
)integer
(orvarint
)
Use [some-type]
in the schema declaration to specify an array
Default values
The following default values are using if your encoded objects misses a property specified in the schema
string = ""
boolean = false
bytes = new Buffer(0)
number = 0
(same for all numbers)array = []
object = {}
License
MIT