Sign in

    moonbitstack/moonrpc/stream does not have a README file

    StreamError

    pub suberror StreamError {
    InvalidTransition(String)
    } derive(Eq)

    An illegal stream transition (RFC 7540 §5.1): a frame not permitted in the current state (typically a STREAM_CLOSED or PROTOCOL_ERROR condition).
    impl Show for StreamError

    StreamError::equal

    fn StreamError::equal(StreamError, StreamError) -> Bool

    StreamError::not_equal

    fn StreamError::not_equal(x : StreamError, y : StreamError) -> Bool

    StreamError::output

    fn StreamError::output(self : StreamError, logger : &Logger) -> Unit

    StreamError::to_string

    fn StreamError::to_string(self : StreamError) -> String

    BidiHandler

    pub(all) struct BidiHandler {
    on_message : (Bytes) -> Array[Bytes]
    on_end : () -> Array[Bytes]
    }

    A live bidirectional call. on_message is invoked once per fully-received request message and returns the reply messages to send right then; on_end runs after the client half-closes and returns the final replies. Both feed the same flow-controlled response stream, so responses interleave with requests.

    Handler

    pub(all) enum Handler {
    Unary((RpcContext, Bytes) -> Bytes)
    ServerStreaming((RpcContext, Bytes) -> Array[Bytes])
    ClientStreaming((RpcContext, Array[Bytes]) -> Bytes)
    Bidi((RpcContext) -> BidiHandler)
    }

    A registered method, in one of gRPC's four cardinalities. The reply shape mirrors the request shape: streaming handlers produce an ordered Array[Bytes] of messages, each framed as its own length-prefixed gRPC message on the wire.

    RpcContext

    pub(all) struct RpcContext {
    path : String
    metadata : Array[
    Header
    ]
    deadline_millis : Int?
    resp_headers : Array[
    Header
    ]
    resp_trailers : Array[
    Header
    ]
    status_fail : (Int, String)?
    error_details : Array[Bytes]
    }

    The context surfaced to a handler for one RPC call: the invoked :path, the request metadata (custom HEADERS, minus the pseudo- and reserved gRPC headers), the deadline parsed from grpc-timeout (in milliseconds, None when absent), and mutable slots for response initial metadata and trailing metadata the handler can set before it returns.

    RpcContext::add_error_detail

    fn RpcContext::add_error_detail(self : RpcContext, detail : Bytes) -> Unit

    Attach a rich-error detail (a serialized google.protobuf.Any) to a failing call. The server packs the status code, message, and every detail into a google.rpc.Status and sends it base64-encoded in the grpc-status-details-bin trailer — gRPC's rich-error channel. Combine with fail, which sets the base grpc-status / grpc-message.

    RpcContext::add_header

    fn RpcContext::add_header(self : RpcContext, name : Bytes, value : Bytes) -> Unit

    Add an initial-metadata header to the response. Only takes effect if called before the response HEADERS are flushed (any point inside a unary / server- / client-streaming handler, or inside a bidi factory before the first message).

    RpcContext::add_trailer

    fn RpcContext::add_trailer(self : RpcContext, name : Bytes, value : Bytes) -> Unit

    Add a trailing-metadata header, sent in the trailer HEADERS alongside grpc-status.

    RpcContext::empty

    fn RpcContext::empty() -> RpcContext

    A context with no path, metadata, or deadline — the placeholder a stream holds until its request HEADERS are decoded.

    RpcContext::fail

    fn RpcContext::fail(self : RpcContext, code : Int, message : String) -> Unit

    End the call with a non-OK gRPC status. A handler calls this (e.g. ctx.fail(Status::code(NotFound), "user 42 does not exist")) instead of returning a normal reply; the server sends the grpc-status / grpc-message trailer and drops the reply message. The five common codes have named helpers on [Status]; any code is accepted.

    RpcContext::metadata_get

    fn RpcContext::metadata_get(self : RpcContext, name : Bytes) -> Bytes?

    The value of request metadata name, or None. Names are matched byte-for-byte (gRPC lowercases header names on the wire), so binary -bin metadata works too.

    Stream

    pub(all) struct Stream {
    id : Int
    state : StreamState
    }

    A mutable stream: its identifier and current lifecycle state. send/recv advance the state in place, raising on an illegal transition.

    Stream::new

    fn Stream::new(id : Int) -> Stream

    A fresh idle stream with the given identifier.

    Stream::recv

    fn Stream::recv(self : Stream, ev : StreamEvent) -> StreamState raise StreamError

    Advance this stream by receiving ev, returning the new state.

    Stream::send

    fn Stream::send(self : Stream, ev : StreamEvent) -> StreamState raise StreamError

    Advance this stream by sending ev, returning the new state.

    StreamEvent

    pub(all) enum StreamEvent {
    Headers(end_stream~ : Bool)
    Data(end_stream~ : Bool)
    Reserve
    RstStream
    } derive(Eq)

    A state-changing stream event: the arrival or departure of the frames that drive §5.1 transitions. Headers/Data carry the END_STREAM flag; Reserve is a PUSH_PROMISE reserving this (promised) stream. Frames that never change stream state (PRIORITY, WINDOW_UPDATE, SETTINGS, PING) are intentionally absent.

    StreamEvent::equal

    fn StreamEvent::equal(StreamEvent, StreamEvent) -> Bool

    StreamEvent::not_equal

    fn StreamEvent::not_equal(x : StreamEvent, y : StreamEvent) -> Bool

    StreamState

    pub(all) enum StreamState {
    Idle
    ReservedLocal
    ReservedRemote
    Open
    HalfClosedLocal
    HalfClosedRemote
    Closed
    } derive(Eq,
    Debug
    )

    The lifecycle state of a single HTTP/2 stream (RFC 7540 §5.1).
    impl Show for StreamState

    StreamState::equal

    fn StreamState::equal(StreamState, StreamState) -> Bool

    StreamState::not_equal

    fn StreamState::not_equal(x : StreamState, y : StreamState) -> Bool

    StreamState::on_recv

    fn StreamState::on_recv(self : StreamState, ev : StreamEvent) -> StreamState raise StreamError

    The next state after receiving ev in this state (RFC 7540 §5.1, remote side — the mirror of on_send). Raises InvalidTransition on an illegal frame.

    StreamState::on_send

    fn StreamState::on_send(self : StreamState, ev : StreamEvent) -> StreamState raise StreamError

    The next state after sending ev from this state (RFC 7540 §5.1, local side). Raises InvalidTransition for a frame illegal in the current state.

    StreamState::output

    fn StreamState::output(self : StreamState, logger : &Logger) -> Unit

    StreamState::to_string

    fn StreamState::to_string(self : StreamState) -> String

    parse_grpc_timeout

    fn parse_grpc_timeout(v : Bytes) -> Int?

    Parse a grpc-timeout value (RFC: up to 8 ASCII digits then a unit — H/M/S/m/u/n) to whole milliseconds, flooring sub-millisecond units. None for a malformed value.

    stream_id_valid_for_initiator

    fn stream_id_valid_for_initiator(id : Int, by_client~ : Bool) -> Bool

    Whether a peer that is a client (by_client = true) or server may legally open stream id: clients use odd ids, servers use even ids, and 0 is the connection control stream, openable by neither (RFC 7540 §5.1.1).

    stream_is_client_initiated

    fn stream_is_client_initiated(id : Int) -> Bool

    Whether id is a client-initiated stream: a non-zero odd identifier.

    stream_is_server_initiated

    fn stream_is_server_initiated(id : Int) -> Bool

    Whether id is a server-initiated (pushed) stream: a non-zero even identifier.