def base64.read

gralha-bytes@0.1.0.1 · bytes.bend:94

import gralha-bytes@0.1.0.1/bytes.bend as Bytes
import Base
import gralha-text-scan@0.1.0.1/scan.bend as U

94def base64.read(+s: String, +bits: U32, +count: U32, +out: Bytes) -> Bytes:
95  match s:
96    case SNil{}: out
97    case SCon{Chr{c}, t}:
98      +v = base64.digit(c)
99      +n = (count + 6 : U32)
100      +word = (bits * 64 + v : U32)
101      U.branch(Bytes, U32.is_eq(c, 61), _ => out,
102        _ => U.branch(Bytes, U.space(c), _ => base64.read(t, bits, count, out),
103          _ => U.branch(Bytes, U32.is_lt(v, 64), _ => U.branch(Bytes, U32.is_ge(n, 8),
104            _ => base64.read(t, U32.mod(word, U32.shln(1, U32.to_nat((n - 8 : U32)))), (n - 8 : U32), bytes.push(out, U32.shrn(word, U32.to_nat((n - 8 : U32))))),
105            _ => base64.read(t, word, n, out)), _ => bytes.empty())))

Uses (19)

Used by (1)