def client.headers.go

bend-kit-http2@0.4.0.0 · http2.bend:360

import bend-kit-http2@0.4.0.0/http2.bend as Http2
import Base
import bend-kit-bytes@0.3.3.0/bytes.bend as Bytes

360def client.headers.go(n: Nat, +first: Bool, +end_stream: Bool, +id: U32, +max: U32, block: Bytes.Bytes, rev: List<&1, Bytes.Bytes>) -> Maybe<&1, List<&1, Bytes.Bytes>>:
361  match n:
362    case 0n:
363      None{}
364    case 1n+p:
365      match block:
366        case Bytes.Bytes{0, buf}:
367          client.headers.empty(first, end_stream, id, max, rev)
368        case Bytes.Bytes{+len, buf}:
369          +take = Bool.pick(U32, U32.is_le(len, max), len, max)
370          +last = U32.is_le(len, max)
371          with_slice(Maybe<&1, List<&1, Bytes.Bytes>>, Bytes.slice(Bytes.Bytes{len, buf}, 0, take), whole => part =>
372            with_slice(Maybe<&1, List<&1, Bytes.Bytes>>, Bytes.slice(whole, take, (len - take : U32)), unused => rest =>
373              Maybe.bind(&1, Bytes.Bytes, List<&1, Bytes.Bytes>,
374                client.frame(encode(max, Frame{Bool.pick(U32, first, 1, 9),
375                  (Bool.pick(U32, last, 4, 0) + Bool.pick(U32, Bool.and(first, end_stream), 1, 0) : U32), id, part})),
376                packet => client.headers.go(p, False{}, end_stream, id, max, rest, Con{packet, rev}))))

Uses (20)

Used by (1)