#import "../types"
Cat = new r.Struct
name: new r.String(r.uint16)
flags: new r.Bitfield(r.uint16, [
'isBlack', 'isStriped'
])
Person = new r.Struct
array: new r.Array(r.uint32, 4)
# numCats: r.uint8
cats: new r.Array(new r.Pointer(r.uint16, Cat, type: 'parent'), r.uint8)
age: r.uint16
fs = require 'fs'
stream = new WritableStream fs.createWriteStream('out.bin')
Person.encode stream,
age: 20
array: [1,2,3,4]
numCats: 2
cats: [
{
name: 'Jasper'
flags:
isBlack: true
}
{
name: 'Piper'
flags:
isStriped: true
}
]
stream.end()
stream.stream.on 'close', ->
read = new Stream fs.readFileSync('out.bin')
console.log read.buffer
console.log require('util').inspect Person.decode(read), false, 50 |