Cbor.encode.go: def of bend-kit-cbor@0.3.0.0 Import: import bend-kit-cbor@0.3.0.0/cbor.bend as Cbor Lines 316-390 of bend-kit-cbor@0.3.0.0/cbor.bend: https://jend.leeeet.dev/read.txt?path=bend-kit-cbor@0.3.0.0/cbor.bend&start_line=316&end_line=390 import Base import bend-kit-bytes@0.3.3.0/bytes.bend as Bytes # fuel bounds the steps; size(v) gives enough, so the 0n arm is never reached. def encode.go(fuel: Nat, items: List<&1, Item>, o: W) -> Maybe<&1, W>: match fuel: case 0n: None{} case 1n+fuel: match items: case Nil{}: Some{o} case Con{IGuard{ok}, rest}: match ok: case True{}: encode.go(fuel, rest, o) case False{}: None{} case Con{IText{value}, rest}: (b, ok) = value Bytes.Bytes{+len, buf} = b encode.go(fuel, Con{IGuard{ok}, rest}, raw.bytes(Bytes.Bytes{len, buf}, head.u32(3, len, o))) case Con{IArrLen{value}, rest}: (xs, n) = value encode.go(fuel, Con{IArr{xs}, rest}, head.u32(4, U32.from_nat(n), o)) case Con{IMapLen{value}, rest}: (kvs, n) = value encode.go(fuel, Con{IMap{kvs}, rest}, head.u32(5, U32.from_nat(n), o)) case Con{IArr{xs}, rest}: match xs: case Nil{}: encode.go(fuel, rest, o) case Con{h, t}: encode.go(fuel, Con{IVal{h}, Con{IArr{t}, rest}}, o) case Con{IMap{kvs}, rest}: match kvs: case Nil{}: encode.go(fuel, rest, o) case Con{(k, v), t}: encode.go(fuel, Con{IVal{k}, Con{IVal{v}, Con{IMap{t}, rest}}}, o) case Con{IVal{value}, rest}: match value: case UInt{value}: encode.go(fuel, rest, uint.bytes(0, value, o)) case NInt{value}: encode.go(fuel, rest, uint.bytes(1, value, o)) case BStr{value}: Bytes.Bytes{+len, buf} = value encode.go(fuel, rest, raw.bytes.go(U32.to_nat(len), Bytes.peek(buf, 0), 0, head.u32(2, len, o))) case TStr{value}: encode.go(fuel, Con{IText{text.check(value)}, rest}, o) case Arr{items}: encode.go(fuel, Con{IArrLen{vals.length(items)}, rest}, o) case Obj{items}: encode.go(fuel, Con{IMapLen{pairs.length(items)}, rest}, o) case Tag{number, value}: encode.go(fuel, Con{IVal{value}, rest}, uint.bytes(6, number, o)) case Sim{value}: match value: case SFalse{}: encode.go(fuel, rest, byte(o, 244)) case STrue{}: encode.go(fuel, rest, byte(o, 245)) case SNull{}: encode.go(fuel, rest, byte(o, 246)) case SUndefined{}: encode.go(fuel, rest, byte(o, 247)) case Other{+value}: encode.go(fuel, Con{IGuard{simple.ok(value)}, rest}, head.u32(7, value, o)) case Flt{value}: match value: case Half{+bits}: encode.go(fuel, Con{IGuard{U32.is_lt(bits, 65536)}, rest}, byte(byte(byte(o, 249), (bits >> 8n : U32)), bits)) case Single{+bits}: encode.go(fuel, rest, raw.u32(byte(o, 250), bits)) case Double{+bits}: W64{+hi, +lo} = bits encode.go(fuel, rest, raw.u32(raw.u32(byte(o, 251), hi), lo)) Uses (28): https://jend.leeeet.dev/definition.txt?path=Base/base.bend&name=Bool https://jend.leeeet.dev/definition.txt?path=Base/base.bend&name=List https://jend.leeeet.dev/definition.txt?path=Base/base.bend&name=Maybe https://jend.leeeet.dev/definition.txt?path=Base/base.bend&name=Nat https://jend.leeeet.dev/definition.txt?path=Base/base.bend&name=Sigma https://jend.leeeet.dev/definition.txt?path=Base/base.bend&name=U32 https://jend.leeeet.dev/definition.txt?path=Base/base.bend&name=U32.from_nat https://jend.leeeet.dev/definition.txt?path=Base/base.bend&name=U32.is_lt https://jend.leeeet.dev/definition.txt?path=Base/base.bend&name=U32.shrn https://jend.leeeet.dev/definition.txt?path=Base/base.bend&name=U32.to_nat https://jend.leeeet.dev/definition.txt?path=bend-kit-bytes@0.3.3.0/bytes.bend&name=Bytes https://jend.leeeet.dev/definition.txt?path=bend-kit-bytes@0.3.3.0/bytes.bend&name=peek https://jend.leeeet.dev/definition.txt?path=bend-kit-cbor@0.3.0.0/cbor.bend&name=Float https://jend.leeeet.dev/definition.txt?path=bend-kit-cbor@0.3.0.0/cbor.bend&name=Item https://jend.leeeet.dev/definition.txt?path=bend-kit-cbor@0.3.0.0/cbor.bend&name=Simple https://jend.leeeet.dev/definition.txt?path=bend-kit-cbor@0.3.0.0/cbor.bend&name=Val https://jend.leeeet.dev/definition.txt?path=bend-kit-cbor@0.3.0.0/cbor.bend&name=W https://jend.leeeet.dev/definition.txt?path=bend-kit-cbor@0.3.0.0/cbor.bend&name=W64 https://jend.leeeet.dev/definition.txt?path=bend-kit-cbor@0.3.0.0/cbor.bend&name=byte https://jend.leeeet.dev/definition.txt?path=bend-kit-cbor@0.3.0.0/cbor.bend&name=head.u32 https://jend.leeeet.dev/definition.txt?path=bend-kit-cbor@0.3.0.0/cbor.bend&name=pairs.length https://jend.leeeet.dev/definition.txt?path=bend-kit-cbor@0.3.0.0/cbor.bend&name=raw.bytes https://jend.leeeet.dev/definition.txt?path=bend-kit-cbor@0.3.0.0/cbor.bend&name=raw.bytes.go https://jend.leeeet.dev/definition.txt?path=bend-kit-cbor@0.3.0.0/cbor.bend&name=raw.u32 https://jend.leeeet.dev/definition.txt?path=bend-kit-cbor@0.3.0.0/cbor.bend&name=simple.ok https://jend.leeeet.dev/definition.txt?path=bend-kit-cbor@0.3.0.0/cbor.bend&name=text.check https://jend.leeeet.dev/definition.txt?path=bend-kit-cbor@0.3.0.0/cbor.bend&name=uint.bytes https://jend.leeeet.dev/definition.txt?path=bend-kit-cbor@0.3.0.0/cbor.bend&name=vals.length