01 / ROUTING
rpc
An RpcServer (config-driven) registers moonrpc Method handlers by gRPC path and dispatches unary calls, returning Unimplemented for unknown methods; RpcGroup registers a set of methods under one package.Service.
WHERE IT SITS
INTERFACE
type RpcHandler = (Bytes) -> BytestypeA unary RPC handler: it maps a request message's wire bytes to a response message's wire bytes (the application/grpc+proto payload, sans the length-prefix framing that @moonrpc.encode_message adds). Streaming handlers arrive with the h2 transport; this is the unary shape zRPC registers today.
type ServerStreamHandler = (Bytes) -> Array[Bytes]typeA server-streaming handler: one request message in, an ordered sequence of response messages out (each framed as its own length-prefixed gRPC message). Mirrors pb.XxxServer server-streaming method, which writes to a grpc.ServerStream instead of returning one reply.
type ClientStreamHandler = (Array[Bytes]) -> BytestypeA client-streaming handler: every request message the client sends is collected, and after the client half-closes the handler returns one reply.
struct BidiStreamHandlerstructA live bidirectional call: on_message fires once per request message and returns the replies to send right then, so responses interleave with requests; on_end runs after the client half-closes and returns the final replies before the grpc-status trailer. The moonzero-local mirror of @moonrpc.BidiHandler, so callers register bidi methods without naming the transport package.
type BidiStreamFactory = () -> BidiStreamHandlertypeA factory that mints one BidiStreamHandler per call, so each stream gets its own handler state.
struct RpcServerstructA zRPC server: config plus a registry mapping each method's gRPC :path (/package.Service/Method) to its handler. Handlers are registered via @moonrpc.Method descriptors — directly or through a RpcGroup — and dispatched by path, mirroring how registers service implementations on the underlying gRPC server. Unary, server-streaming, and client-streaming methods live in separate registries so one path resolves to exactly one cardinality.
fn RpcServer::new(conf : @conf.RpcServerConf) -> RpcServerfnBuild an empty RPC server from its config.
fn RpcServer::with_interceptors( self : RpcServer, interceptors : Array[Interceptor]) -> RpcServerfnA server whose unary calls run through interceptors, outermost first.
fn RpcServer::use_( self : RpcServer, interceptor : Interceptor) -> RpcServerfnA server with interceptor added at the front of the chain, so the layers are named from the outermost in.
fn RpcServer::interceptors(self : RpcServer) -> Array[Interceptor]fnThe interceptors this server's unary calls run through, outermost first.
fn RpcServer::of( conf : @conf.RpcServerConf, deps~ : ServerDeps = ServerDeps::new() catch { _ => abort("server deps") }) -> RpcServerfnBuild a server from conf with the chain its Middlewares flags ask for.
fn RpcServer::invoke( self : RpcServer, call : Call) -> Result[Bytes, @moonrpc.Status]fnDispatch one unary call through the interceptor chain, then the registered handler. An unregistered path answers Unimplemented from the innermost invoker, so the chain still sees and records it.
fn RpcServer::conf(self : RpcServer) -> @conf.RpcServerConffnThe server's configuration.
fn RpcServer::register( self : RpcServer, desc : @moonrpc.Method, handler : RpcHandler) -> UnitfnRegister handler for method, keyed by its gRPC path. A later registration for the same path replaces the earlier one.
fn RpcServer::register_server_streaming( self : RpcServer, desc : @moonrpc.Method, handler : ServerStreamHandler) -> UnitfnRegister a server-streaming handler for method, keyed by its gRPC path.
fn RpcServer::register_client_streaming( self : RpcServer, desc : @moonrpc.Method, handler : ClientStreamHandler) -> UnitfnRegister a client-streaming handler for method, keyed by its gRPC path.
fn RpcServer::register_bidi_streaming( self : RpcServer, desc : @moonrpc.Method, factory : BidiStreamFactory) -> UnitfnRegister a bidirectional-streaming handler for method, keyed by its gRPC path. factory runs once per call so each stream gets fresh handler state.
fn RpcServer::group(self : RpcServer, service : String) -> RpcGroupfnOpen a RpcGroup that registers methods under the fully-qualified package.Service name — per-service registration, without repeating the service name on each method.
fn RpcServer::lookup(self : RpcServer, path : String) -> RpcHandler?fnLook up the handler registered for a gRPC :path, or None if unregistered.
fn RpcServer::methods(self : RpcServer) -> Array[String]fnThe gRPC paths of every registered method.
fn RpcServer::has_method(self : RpcServer, path : String) -> BoolfnWhether a handler is registered for path.
fn RpcServer::dispatch( self : RpcServer, path : String, request : Bytes) -> Result[Bytes, @moonrpc.Status]fnDispatch a unary call to the handler registered for path, returning the response bytes. An unregistered path yields Err(Unimplemented) — exactly the grpc-status a real gRPC server returns for an unknown method — so a transport can translate the result straight onto the wire.
struct RpcGroupstructA per-service registration handle: binds a set of methods to one package.Service on a shared RpcServer.
fn RpcGroup::service(self : RpcGroup) -> StringfnThe fully-qualified package.Service this group registers under.
fn RpcGroup::register( self : RpcGroup, name : String, handler : RpcHandler) -> UnitfnRegister a method name on this group's service, building the @moonrpc.Method descriptor and installing handler under its gRPC path. (register, not method — the latter is a reserved word.)
fn RpcGroup::register_server_streaming( self : RpcGroup, name : String, handler : ServerStreamHandler) -> UnitfnRegister a server-streaming method name on this group's service.
fn RpcGroup::register_client_streaming( self : RpcGroup, name : String, handler : ClientStreamHandler) -> UnitfnRegister a client-streaming method name on this group's service.
fn RpcGroup::register_bidi_streaming( self : RpcGroup, name : String, factory : BidiStreamFactory) -> UnitfnRegister a bidirectional-streaming method name on this group's service.
fn RpcServer::dispatch_graceful( self : RpcServer, coord : @proc.ShutdownCoordinator, path : String, request : Bytes) -> Result[Bytes, @moonrpc.Status]fnDispatch a unary call through the shutdown gate: refuse with Unavailable when the server is shutting down, otherwise run the handler and count it as in-flight for the duration so a concurrent shutdown drains behind it. The gate wraps RpcServer::dispatch, so an unregistered path still yields Unimplemented.