Sign in

    moonbitstack/moonrpc/client does not have a README file

    CallReply

    pub(all) struct CallReply {
    status : Bytes
    grpc_status : Int
    grpc_message : String
    headers : Array[
    Header
    ]
    messages : Array[Bytes]
    trailers : Array[
    Header
    ]
    }

    The completed result of a call: the HTTP :status, the numeric grpc-status (-1 if the peer never sent one), the response initial metadata, the reply messages in order, and the trailing metadata.

    ClientCall

    pub(all) struct ClientCall {
    id : Int
    path : Bytes
    authority : Bytes
    metadata : Array[
    Header
    ]
    timeout : Bytes?
    out : Bytes
    out_off : Int
    req_ended : Bool
    req_headers_sent : Bool
    req_fin_sent : Bool
    send_window : Int
    data :
    Buffer

    data_off : Int
    messages : Array[Bytes]
    recv_window : Int
    status : Bytes
    grpc_status : Int?
    grpc_message : String
    resp_encoding : Bytes
    resp_headers : Array[
    Header
    ]
    resp_trailers : Array[
    Header
    ]
    headers_seen : Bool
    header_block :
    Buffer

    in_headers : Bool
    pending_end_stream : Bool
    decode_failed : Bool
    retryable : Bool
    done : Bool
    }

    One client-side call: its stream id, the request side (the length-prefixed request body still to send, the send window, and whether the request has been half-closed), and the response side (the accumulating DATA with a cursor over the messages already pulled out, the recv window, the captured :status and grpc-status, and the response initial and trailing metadata).

    H2Client

    pub struct H2Client {
    encoder :
    Encoder

    decoder :
    Decoder

    calls : Map[Int, ClientCall]
    next_id : Int
    conn_send_window : Int
    conn_recv_window : Int
    remote_initial_window : Int
    remote_max_frame : Int
    goaway_received : Bool
    goaway_last_stream_id : Int
    orphan_blocks : Map[Int,
    Buffer
    ]
    }

    The client side of one HTTP/2 connection: the HPACK codec pair (stateful across every call on the connection), the live calls keyed by stream id, the next odd stream id to allocate (§5.1.1), and the connection-level flow-control state bounded by the peer's SETTINGS.

    H2Client::close_send

    fn H2Client::close_send(self : H2Client, id : Int) -> Array[
    Frame
    ]

    Half-close the request side of a call (no more request messages) and return any frames that completes — the trailing END_STREAM.

    H2Client::feed

    Feed one decoded response frame to the engine, advancing all state and returning the frames to write back (SETTINGS ack, PING pong, WINDOW_UPDATE replenishing a receive window, and — once a WINDOW_UPDATE lifts back-pressure — any remaining request DATA). Captures :status, grpc-status, response metadata, and the reassembled reply messages.

    H2Client::goaway_last_stream_id

    fn H2Client::goaway_last_stream_id(self : H2Client) -> Int

    The peer's last processed stream id from its GOAWAY (0 if none was seen); a call whose stream id is above it was never handled by the server.

    H2Client::goaway_received

    fn H2Client::goaway_received(self : H2Client) -> Bool

    Whether the peer has sent GOAWAY; a draining connection opens no new stream, so the driver picks a fresh one for further calls. Mirrors H2Server::goaway_received.

    H2Client::has_messages

    fn H2Client::has_messages(self : H2Client, id : Int) -> Bool

    Whether a call has reply messages buffered but not yet taken — for reading a streaming response incrementally as it arrives, rather than all at once via reply.

    H2Client::is_done

    fn H2Client::is_done(self : H2Client, id : Int) -> Bool

    Whether a call has fully completed (its response ended). An unknown id counts as done so a driver loop terminates.

    H2Client::is_retryable

    fn H2Client::is_retryable(self : H2Client, id : Int) -> Bool

    Whether call id was left retryable by a GOAWAY: its stream id is above the peer's last processed id, so the server never saw it and re-issuing the RPC on a fresh connection is safe (gRPC transport GOAWAY / RFC 7540 §6.8). False for a call at or below that id — it may have been processed — and when no GOAWAY arrived.

    H2Client::new

    fn H2Client::new() -> H2Client

    A fresh client engine with no live calls. The first call takes stream id 1.

    H2Client::open

    fn H2Client::open(self : H2Client, path : String, metadata? : Array[
    Header
    ], authority? : String, timeout_millis? : Int) -> Int

    Open a new call on this connection for path (/pkg.Service/Method), returning its freshly allocated stream id. metadata is sent as custom request HEADERS; timeout_millis, when set, becomes the grpc-timeout header. The request body is added with send and half-closed with close_send.

    H2Client::preface

    The client's opening frames (RFC 7540 §3.5): a SETTINGS frame disabling server push. Written right after the 24-octet connection @http2.preface bytes, before any request.

    H2Client::release

    fn H2Client::release(self : H2Client, id : Int) -> Unit

    Drop everything the engine still holds for a finished call: its buffered body, messages, header block and trailers. The map is only ever inserted into otherwise, so a long-lived connection would keep one full request and response per RPC it has ever made, and every WINDOW_UPDATE and SETTINGS frame would walk that whole history. An unknown or already-released id is a no-op.

    H2Client::reply

    fn H2Client::reply(self : H2Client, id : Int) -> CallReply

    The completed result of a call. Meaningful once is_done is true.

    H2Client::send

    fn H2Client::send(self : H2Client, id : Int, message : Bytes, end? : Bool) -> Array[
    Frame
    ]

    Append one request message to a call and return the frames to write now (the request HEADERS the first time, then as much length-prefixed DATA as the send windows allow). Set end on the last message to half-close the request.

    H2Client::take_messages

    fn H2Client::take_messages(self : H2Client, id : Int) -> Array[Bytes]

    Take every reply message received so far, clearing the call's buffer — the incremental counterpart to reply, for a server- or bidi-streaming response read message by message.

    H2Client::unary

    fn H2Client::unary(self : H2Client, path : String, request : Bytes, metadata? : Array[
    Header
    ], authority? : String, timeout_millis? : Int) -> (Int, Array[
    Frame
    ])

    Open a unary call and return (stream_id, frames_to_write) in one step: the request HEADERS and the single length-prefixed request message with END_STREAM.

    encode_grpc_timeout

    fn encode_grpc_timeout(millis : Int) -> Bytes

    Encode whole millis as a grpc-timeout header value (RFC gRPC HTTP/2 mapping): the m (millisecond) unit when the count fits the 8-digit field, else seconds with the S unit.

    percent_decode

    fn percent_decode(v : Bytes) -> String

    Percent-decode a received grpc-message value — the inverse of the server's percent_encode (gRPC spec §"Responses"): each %XX escape becomes the byte its two hex digits name, every other byte passes through, and a malformed escape is left literal; the result is read as UTF-8.

    Source Files