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.
--file=PROTO_BIN_FILE
Argument 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.
--search-dir=PROTO_DIR
Argument 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
).
--namespace-base=NS_BASE
Argument 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
.
--file-extension=EXT
Argument The extension to use for the generated C# files. Default is .g.cs
.
--build-protoc
Argument --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
.
--proto-import=IMP_DIR
Argument 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.
--proto-extension=EXT
Argument 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
.
--error-format=FORMAT
Argument 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 |
--ignore-unwrap=TYPE
Argument 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.
--empty-support
Argument 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.
-v
, --verbose
Argument Print more information about the build process. This is useful for debugging your code.
-h
, --help
Argument Print the help documentation to your console.