moonbitstack/moonctl/proto does not have a README file

    GatewayRoute

    pub(all) struct GatewayRoute {
    verb : String
    path : String
    rpc : String
    }

    One HTTP route and the gRPC method behind it: the verb and path the gateway answers, and the fully-qualified method it forwards to.

    Label

    pub(all) enum Label {
    Single
    Repeated
    MapOf(key~ : String, value~ : String)
    } derive(Eq,
    Debug
    )

    Whether a field holds one value, a list, or a map with proto key and value types.

    Label::equal

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

    Label::not_equal

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

    Label::to_repr

    Proto

    pub(all) struct Proto {
    package_ : String
    services : Array[ProtoService]
    messages : Array[ProtoMessage]
    enums : Array[ProtoEnum]
    }

    A parsed .proto file: its package (empty when none) and the services and messages it declares.

    ProtoEnum

    pub(all) struct ProtoEnum {
    name : String
    values : Array[ProtoEnumValue]
    }

    A protobuf enum declaration, generated into a MoonBit enum plus an integer mapping (proto3 enums are int-backed, and the value numbered 0 is the default).

    ProtoEnumValue

    pub(all) struct ProtoEnumValue {
    name : String
    number : Int
    }

    One value of a protobuf enum: its name and its integer number.

    ProtoField

    pub(all) struct ProtoField {
    name : String
    type_ : String
    proto : String
    label : Label
    number : Int
    }

    One field of a protobuf message: its name, its MoonBit type (repeated is Array[T], map<K, V> is Map[K, V]), its proto element type as written, its label and its wire number.

    ProtoMessage

    pub(all) struct ProtoMessage {
    name : String
    fields : Array[ProtoField]
    oneofs : Array[ProtoOneof]
    reserved_numbers : Array[Int]
    reserved_names : Array[String]
    }

    A protobuf message declaration, generated into a MoonBit struct. oneof groups are lifted out of fields into oneofs; reserved field numbers and names are recorded so a reused one can be caught.

    ProtoOneof

    pub(all) struct ProtoOneof {
    name : String
    variants : Array[ProtoField]
    }

    A protobuf oneof group: its name and the members (exactly one may be set). Generated into a MoonBit enum — the faithful equivalent of the "exactly one" invariant, which flattening to optional fields would lose.

    ProtoService

    pub(all) struct ProtoService {
    name : String
    rpcs : Array[Rpc]
    }

    A protobuf service declaration and its RPC methods.

    Rpc

    pub(all) struct Rpc {
    name : String
    request : String
    response : String
    client_streaming : Bool
    server_streaming : Bool
    }

    One rpc method of a service: its name, request and response message names, and whether either side is a stream (client/server/bidi streaming).

    commas

    fn commas(parts : Array[String]) -> String

    Join parts with ", " — the codegen workhorse for column/argument lists.

    default_routes

    fn default_routes(proto : Proto) -> Array[GatewayRoute]

    Every RPC of proto as the default route: POST /<Service>/<Method> — the gRPC path with its package dropped, because a gateway in front of one package does not need the package repeated in the URL. A POST is the method gRPC itself uses, so the mapping is the one that always works.

    gateway_file_name

    fn gateway_file_name(proto_path : String) -> String

    The file a gateway lands in: the .proto's own name, without its directory and without its extension — proto/greet.proto → greet_gateway.mbt. A .proto may declare several services, so the file name comes from the file rather than from one of them.

    generate_gateway

    fn generate_gateway(proto : Proto, routes : Array[GatewayRoute]) -> String

    Generate the gateway for proto with routes: the route table, the gateway itself, and the two entry points — handle, which takes a JSON body already parsed, and handle_text, which parses the body a request carried.

    Status codes are the four an HTTP client cares about: 200 for a reply, 400 for a body that is not JSON, 404 for a path no route answers, and 502 for a call the upstream failed. A gRPC status does not leak through: an HTTP client reads it where it is meaningful — in the reply body.

    generate_grpc

    fn generate_grpc(proto : Proto) -> String

    Generate a moonrpc service stub from a parsed .proto: a MoonBit struct per message, a @moonrpc.Method descriptor per RPC (its gRPC :path is /package.Service/Method), a <Service>Server handler-registration struct (one synchronous-core handler field per RPC, each returning its reply or a gRPC @moonrpc.Status), and a <service>_methods() listing. The output compiles against moonbitstack/moonrpc.

    has_method

    fn has_method(proto : Proto, target : String) -> Bool

    Whether proto declares the gRPC method target (/package.Service/Method), so a hand-written route that names a method the spec does not have is caught here rather than at the first request.

    parse_proto

    fn parse_proto(source : String) -> Proto

    Parse a minimal .proto (proto3). Recognises the package declaration, service blocks with their rpc methods (including stream), message blocks with scalar/repeated/map fields, and top-level enum declarations. syntax, import, and option are skipped.

    syntax = "proto3"; package greet; service Greeter { rpc SayHello (HelloRequest) returns (HelloReply); } message HelloRequest { string name = 1; } message HelloReply { string message = 1; }

    parse_route_map

    fn parse_route_map(proto : Proto, source : String) -> (Array[GatewayRoute], Array[String])

    The routes a mapping file declares, in the order it declares them. A line is VERB /path /package.Service/Method; # starts a comment, and a blank line is skipped. A line naming a method the .proto does not declare, or one that streams, is left out — skipped reports it so the caller can say which.

    proto_reserved_conflicts

    fn proto_reserved_conflicts(m : ProtoMessage) -> Array[String]

    The names of m's fields (oneof members included) that reuse a reserved field number or name — protobuf forbids reusing either, and this surfaces an accidental reuse. Empty when the message is clean.

    Powered by MoonBit

    Site sourceReport issueModulesSkillsBuild queueStatistics

    © 2026 mooncakes.io