def b64go

bendonnect-rpc@0.1.0.0 · src/protocol.bend:498

import bendonnect-rpc@0.1.0.0/src/protocol.bend as Protocol
import Base
import bend-kit-bytes@0.3.2.0/bytes.bend as Bytes

498# Fills out from the 6-bit values; None on a dangling single char.
499def b64go(vs: List<&2, U32>, out: Bytes.Bytes, +i: U32) -> Maybe<&1, Bytes.Bytes>:
500  match vs:
501    case Nil{}:
502      Some{out}
503    case Con{+a, Nil{}}:
504      None{}
505    case Con{+a, Con{+b, Nil{}}}:
506      Some{b64set(out, i, ((a << 2n) .|. (b >> 4n) : U32))}
507    case Con{+a, Con{+b, Con{+c, Nil{}}}}:
508      Some{b64set(b64set(out, i, ((a << 2n) .|. (b >> 4n) : U32)), (i + 1 : U32), (((b .&. 15 : U32) << 4n) .|. (c >> 2n) : U32))}
509    case Con{+a, Con{+b, Con{+c, Con{+d, rest}}}}:
510      b64go(rest, b64set(b64set(b64set(out, i, ((a << 2n) .|. (b >> 4n) : U32)), (i + 1 : U32), (((b .&. 15 : U32) << 4n) .|. (c >> 2n) : U32)), (i + 2 : U32), (((c .&. 3 : U32) << 6n) .|. d : U32)), (i + 3 : U32))

Uses (10)

Used by (1)