def w.done

bend-kit-json@0.7.0.0 · json.bend:62

import bend-kit-json@0.7.0.0/json.bend as Json
import Base
import bend-kit-bytes@0.3.3.0/bytes.bend as Bytes

62# Stores the last partial word, then copies into the fewest words, as Bytes requires.
63def w.done(o: W) -> Bytes.Bytes:
64  W{buf, +cap, +n, +w} = o
65  +r = (n .&. 3 : U32)
66  +k = (n >> 2n : U32)
67  +g = U32.is_ne(r, 0) && U32.is_eq(k, cap)
68  +cap2 = Bool.pick(U32, g, (cap * 2 : U32), cap)
69  out = Bytes.flush(U32.is_ne(r, 0), w.room(g, buf, k), k, U32.shrn(w, U32.to_nat((((4 - r) .&. 3) * 8 : U32))))
70  Bytes.Bytes{n, w.shrink(U32.is_eq(U32.shln(1, Bytes.depth(Bytes.words(n))), cap2), n, out)}

Uses (18)

Used by (3)