def client.data.go

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

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

395def client.data.go(n: Nat, body: Bytes.Bytes, take: U32, +id: U32, +max: U32,
396    +connection: U32, +stream: U32, rev: List<&1, Bytes.Bytes>) -> Maybe<&1, BodySent>:
397  match n:
398    case 0n:
399      None{}
400    case 1n+p:
401      match body:
402        case Bytes.Bytes{0, buf}:
403          Some{BodySent{Bytes.Bytes{0, buf}, True{}, stream, connection, List.reverse(&1, Bytes.Bytes, rev)}}
404        case Bytes.Bytes{+len, buf}:
405          match take:
406            case 0:
407              Some{BodySent{Bytes.Bytes{len, buf}, False{}, stream, connection, List.reverse(&1, Bytes.Bytes, rev)}}
408            case +count:
409              with_slice(Maybe<&1, BodySent>, Bytes.slice(Bytes.Bytes{len, buf}, 0, count), whole => part =>
410                with_slice(Maybe<&1, BodySent>, Bytes.slice(whole, count, (len - count : U32)), unused => rest =>
411                  Maybe.bind(&1, Bytes.Bytes, BodySent,
412                    client.frame(encode(max, Frame{0, Bool.pick(U32, U32.is_eq(count, len), 1, 0), id, part})), packet =>
413                      +new_connection = (connection - count : U32)
414                      +new_stream = (stream - count : U32)
415                      +remaining = (len - count : U32)
416                      client.data.go(p, rest, client.available(remaining, max, new_connection, new_stream),
417                        id, max, new_connection, new_stream, Con{packet, rev}))))

Uses (20)

Used by (1)