Sign in

    moonbitstack/moonrpc/wire does not have a README file

    Keepalive

    pub struct Keepalive {
    keepalive_time : Int64
    keepalive_timeout : Int64
    last_activity : Int64
    ping_outstanding : Bool
    ping_sent_at : Int64
    }

    Keepalive state for one connection: the idle threshold that triggers a PING, the ACK deadline that declares the connection dead, and the timers tracking the last activity and any in-flight PING.

    Keepalive::is_timed_out

    fn Keepalive::is_timed_out(self : Keepalive, now : Int64) -> Bool

    Whether the connection is dead at now: a PING is outstanding and its ACK has not arrived within keepalive_timeout of sending it.

    Keepalive::new

    fn Keepalive::new(keepalive_time~ : Int64, keepalive_timeout~ : Int64, now? : Int64) -> Keepalive

    A keepalive that pings after keepalive_time of idleness and gives a PING keepalive_timeout to be acknowledged. now seeds the activity clock.

    Keepalive::on_activity

    fn Keepalive::on_activity(self : Keepalive, now : Int64) -> Unit

    Record connection activity (a frame sent or received) at now, resetting the idle timer.

    Keepalive::on_ping_ack

    fn Keepalive::on_ping_ack(self : Keepalive, now : Int64) -> Unit

    Record that the PING's ACK arrived at now — the connection is alive, and this counts as activity.

    Keepalive::on_ping_sent

    fn Keepalive::on_ping_sent(self : Keepalive, now : Int64) -> Unit

    Record that a keepalive PING was sent at now.

    Keepalive::should_ping

    fn Keepalive::should_ping(self : Keepalive, now : Int64) -> Bool

    Whether a keepalive PING should be sent at now: the connection has been idle at least keepalive_time and no PING is already awaiting its ACK.

    Method

    pub(all) struct Method {
    service : String
    name : String
    }

    A fully-qualified RPC method: package.Service and the method name.

    Method::path

    fn Method::path(self : Method) -> String

    The gRPC HTTP/2 :path, i.e. /package.Service/Method.

    Status

    pub(all) enum Status {
    Ok
    Cancelled
    Unknown
    InvalidArgument
    DeadlineExceeded
    NotFound
    AlreadyExists
    PermissionDenied
    ResourceExhausted
    FailedPrecondition
    Aborted
    OutOfRange
    Unimplemented
    Internal
    Unavailable
    DataLoss
    Unauthenticated
    } derive(Eq)

    The 17 canonical gRPC status codes (grpc-status).

    Status::code

    fn Status::code(self : Status) -> Int

    The numeric grpc-status code.

    Status::equal

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

    Status::from_h2_error

    fn Status::from_h2_error(code : Int) -> Status

    The status a call ends with when the peer resets its stream instead of sending trailers, from the RST_STREAM error code (gRPC PROTOCOL-HTTP2, "HTTP2 Error Code → Status"). A refused stream was never processed, so it is UNAVAILABLE and safe to retry; anything the table does not name is INTERNAL, since the peer broke the transport rather than the call.

    Status::from_http

    fn Status::from_http(code : Int) -> Status

    The status a non-200 HTTP response maps to when it carries no grpc-status — a proxy or a plain HTTP server answering on the gRPC port (gRPC http-grpc-status-mapping). Anything outside the table is UNKNOWN.

    Status::name

    fn Status::name(self : Status) -> String

    The canonical uppercase status name.

    Status::not_equal

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

    decode_message

    fn decode_message(data : Bytes) -> (Bool, Bytes)?

    Decode one gRPC length-prefixed message from the front of data, returning (compressed, payload), or None if fewer than a full frame is present.

    default_max_frame_size

    let default_max_frame_size : Int

    The HTTP/2 default (and minimum) SETTINGS_MAX_FRAME_SIZE (RFC 7540 §6.5.2).

    default_window_size

    let default_window_size : Int

    The HTTP/2 default flow-control window and initial SETTINGS_INITIAL_WINDOW_SIZE (RFC 7540 §6.9.2): 65 535 octets.

    encode_message

    fn encode_message(payload : Bytes, compressed? : Bool) -> Bytes

    Encode a payload as a gRPC Length-Prefixed-Message: a 1-byte compression flag, a 4-byte big-endian length, then the payload. This is the framing every gRPC transport shares (gRPC-Web over HTTP/1.1 and real gRPC over HTTP/2 alike).

    is_binary_metadata

    fn is_binary_metadata(name : Bytes) -> Bool

    True when a metadata key carries binary, which gRPC spells by suffixing the key with -bin.

    max_header_list_size

    let max_header_list_size : Int

    The cap on one accumulated header block (HEADERS plus its CONTINUATION frames). Without it a peer could stream endless non-final CONTINUATION frames and grow the buffer without bound (a CONTINUATION flood); 128 KiB is far above any real gRPC request's headers.

    max_message_size

    let max_message_size : Int

    The default cap on a single received gRPC message (4 MiB, matching gRPC's default MaxRecvMsgSize). A length prefix above this — including one whose 4 bytes decode to a negative Int because the high bit is set — is rejected rather than trusted, so a hostile prefix can neither slice out of bounds nor pin unbounded buffer.

    message_len

    fn message_len(data : BytesView, at? : Int) -> Int?

    The payload length of the length-prefixed message at at, or None when fewer than the five octets of a prefix are there.

    A prefix with its high bit set reads back negative, which is how a hostile length is told from a real one before anything is sliced on it. Every reader of this framing goes through here — there are five of them across the client, the server and the socket transport, and they have to agree.

    metadata_value_from_wire

    fn metadata_value_from_wire(name : Bytes, value : Bytes) -> Bytes

    Decode a metadata value coming off the wire: base64 for a -bin key, verbatim otherwise.

    Padding is optional on the wire, and a peer may pad or not; anything outside the alphabet is skipped rather than rejected, which is what the gRPC spec asks a receiver to tolerate.

    metadata_value_to_wire

    fn metadata_value_to_wire(name : Bytes, value : Bytes) -> Bytes

    Encode a metadata value for the wire: base64 for a -bin key, verbatim otherwise.

    split_messages

    fn split_messages(data : Bytes) -> Array[Bytes]

    Split a run of concatenated length-prefixed messages into their payloads, stopping at the first one that has not fully arrived.