// A cache of orders kept as MessagePack, smaller than JSON, and read back.
//
//   quillo run msgpack.qwe      then open http://localhost:8080/sizes

use "msgpack.qwer"

let orders = range(50) | map((i) => { id: i, customer: `customer-${i}`, total: 10.5 + i, paid: i % 2 == 0, items: [i, i + 1] })

route GET /sizes {
    let bytes = msgpack_write_file("data/orders.msgpack", orders)?
    let back = msgpack_read_file("data/orders.msgpack")?
    { msgpack_bytes: bytes, json_bytes: len(json.stringify(orders)), same: back == orders, third: back[2] }
}

route GET /roundtrip {
    let packed = msgpack_encode({ event: "signup", user: 7, at: "2026-11-02T09:00:00Z", tags: ["beta"] })?
    { packed, back: msgpack_decode(packed)? }
}
