Programming Language

Nocter

A self-contained systems language built around simplicity, encapsulation, and foolproof design.

application.nct

see ./index.nct

use std/fs
use std/cli.Application
use std/vec.Vec

async func run(): i32 {
    var application = Application.new("binary-record", "Round-trip a binary record log.") catch _ { return 2 }
    application.add_positional("PATH", true, "Temporary record path.") catch _ { return 2 }
    let arguments = application.parse_process() catch _ { return 2 }
    let path = arguments.positional("PATH") otherwise { return 2 }

    let records: Vec<Record> = Vec [
        Record.new(42, 3.5),
        Record.new(7, -1.25),
    ]
    let encoded = encode_log(&records as &[Record]) catch _ { return 2 }
    await fs.write(path, &encoded as &[u8]) catch _ { return 2 }
    let stored = await fs.read(path) catch _ { return 2 }
    var fragmented = FragmentedBytes.new(&stored as &[u8], 2)
    let decoded = await decode_async(&+fragmented) catch _ { return 2 }
    match decoded.tail() {
        RecordTail.complete {
            if decoded.len() != 2 { return 2 }
        }
        _ { return 2 }
    }
    let last = decoded.record(1) otherwise { return 2 }
    if last.item_count() != 7 || last.measurement().to_bits() != 13831680355561635840 {
        return 2
    }
    return 0
}

async func main(): i32! {
    return await run()
}