all files / fontkit/playground/ types.coffee

0% Statements 0/10
100% Branches 0/0
0% Functions 0/1
0% Lines 0/10
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41                                                                                 
#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