def size

bend-kit-cbor@0.3.0.0 · cbor.bend:286

import bend-kit-cbor@0.3.0.0/cbor.bend as Cbor
import Base

286# v, and at least the number of encode.go steps it takes.
287def size(v: Val) -> Val & Nat:
288  match v:
289    case Arr{items}:
290      match items:
291        case Nil{}:
292          (Arr{Nil{}}, 3n)
293        case Con{h, t}:
294          size.cons(size(h), size(Arr{t}))
295    case Obj{items}:
296      match items:
297        case Nil{}:
298          (Obj{Nil{}}, 3n)
299        case Con{(k, x), t}:
300          size.pair(size(k), size(x), size(Obj{t}))
301    case Tag{number, value}:
302      size.tag(number, size(value))
303    case UInt{value}:
304      (UInt{value}, 3n)
305    case NInt{value}:
306      (NInt{value}, 3n)
307    case BStr{value}:
308      (BStr{value}, 3n)
309    case TStr{value}:
310      (TStr{value}, 3n)
311    case Sim{value}:
312      (Sim{value}, 3n)
313    case Flt{value}:
314      (Flt{value}, 3n)

Uses (8)

Used by (1)