def decode
import bend-kit-cbor@0.3.0.0/cbor.bend as Cborimport Base
import bend-kit-bytes@0.3.3.0/bytes.bend as Bytes
779# One well-formed data item (RFC 8949 §3, Appendix C) filling b. Indefinite strings, arrays and maps come back
780# definite, with chunks joined. None for truncation, reserved ai 28..30, a misplaced break or indefinite form,
781# a simple value 0..31 in two bytes, text that is not UTF-8, or trailing bytes.
782# fuel: a head or chunk eats a byte, and each SDone step follows one, so 2 * len + 2 steps are enough.
783def decode(b: Bytes.Bytes) -> Maybe<&1, Val>:
784 Bytes.Bytes{+len, buf} = b
785 run(Nat.add(Nat.mul(U32.to_nat(len), 2n), 2n), (buf, SHead{0, Nil{}}), len)