Sign in

    moonbitstack/moonctl/proto does not have a README file

    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.

    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.

    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; }

    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.

    Source Files