sRPCgen - Garados007/srpc GitHub Wiki

sRPCgen is a small util that can generate the C# API implementation out of your service declaration in your proto files. For this to work it needs the binary descriptor information of your proto that can generated like this:

protoc \
    --proto_path=path/of/your/imports \
    --descriptor_set_out=path/of/new/descriptor/file \
    --include_imports \
    path/to/your/proto/file

It is important to include the parameter --include_imports if your proto definition imports messages from other proto files. Otherwise sRPCgen is not able to find all the required information about your used types.

If you include the argument --build-protoc to the sRPCgen call, sRPCgen will automaticly call protoc to generate its required descriptor information. So there is no need to call protoc first.

Argument --file=PROTO_BIN_FILE

Specify the descriptor file for the protobuf implementation of the RPC interface. This file cas to contain all required imports. This file can generated with protoc and the --descriptor_set_out option.

This option is automaticly set if you add a file name as an argument.

Argument --search-dir=PROTO_DIR

Will search for all suitable files in the dictionary and parse them. This works as if you search each file manually and call this process with --file.

This argument cannot combined with the --file argument!

This argument expects the files to have the extension .proto.bin (.proto if you use --build-protoc).

Argument --namespace-base=NS_BASE

The base name for the output namespace. This is only used to determine the output file name and will shorten the path. If not set the whole namespace of the service will recreated as a directory structure.

Example:

If the full name of your service is foo.bar.Baz, --namespace-base=foo will locate the file in bar/Baz.cs.

Argument --file-extension=EXT

The extension to use for the generated C# files. Default is .g.cs.

Argument --build-protoc

--file and --search-dir will work directly with the .proto files. This expects to have the protoc in the PATH environment variable or your current working directory.

--search-dir will now search for .proto files instead of .proto.bin.

Argument --proto-import=IMP_DIR

Only if --build-protoc is defined.

This will add the --proto_path=IMP_DIR argument to the protoc call. IMP_DIR is the path of the protoc import files.

This argument can be defined multiple times.

Argument --proto-extension=EXT

Only if --build-protoc is defined.

This will add the file_extension=EXT to the --csharp_opt argument to the protoc call. EXT is the extension of the C# file generated by protoc.

Default is .cs.

Argument --error-format=FORMAT

Set the error output format for sRPCgen and protoc. Only the following formats are supported:

Format Description
default The default format for the output
msvs The output format that is used by Microsoft Visual Studio

Argument --ignore-unwrap=TYPE

sRPCgen will try to generate Api client calls with unwrapped request messages. The user can call methods like this:

// explicit creation of request messages
var response = await api.RandomNumbers(new RandomNumbersRequest
{
    Count = 15,
    MinValue = 0,
    MaxValue = 100,
});
// unwrapped call. The Api method will create the request message for you
var response = await api.RandomNumbers(count: 15, minValue: 0, maxValue: 100);

If you intend that some request messages should not have an unwrapped call, you can add this argument to the build. This argument can be defined more than once for different types. The type name is the complete protobuf type name including the package name.

It is recommended to ignore empty types like google.protobuf.Empty. If you define the argument --empty-support the type google.protobuf.Empty is automaticly ignored.

Argument --empty-support

Adds special support for the type google.protobuf.Empty. If this is set any request or response that are of this type will be omit in the user Api. This simplify the usage with the generated code.

The messages that are sent with this support are identical without this support.

Argument -v, --verbose

Print more information about the build process. This is useful for debugging your code.

Argument -h, --help

Print the help documentation to your console.