GodotRosettaRpc 0.1.1
dotnet add package GodotRosettaRpc --version 0.1.1
NuGet\Install-Package GodotRosettaRpc -Version 0.1.1
<PackageReference Include="GodotRosettaRpc" Version="0.1.1" />
<PackageVersion Include="GodotRosettaRpc" Version="0.1.1" />
<PackageReference Include="GodotRosettaRpc" />
paket add GodotRosettaRpc --version 0.1.1
#r "nuget: GodotRosettaRpc, 0.1.1"
#:package GodotRosettaRpc@0.1.1
#addin nuget:?package=GodotRosettaRpc&version=0.1.1
#tool nuget:?package=GodotRosettaRpc&version=0.1.1
godot-rosetta-rpc (C# runtime)
The C# runtime for the godot-rosetta-rpc cross-language RPC
framework: RpcMethodDescriptor, ServiceRegistry, RpcClient, plus a
GodotSupport static class to plug in the rest of the library with Godot.
This library never depends on any project-specific generated code.
Installing
<ItemGroup>
<PackageReference Include="GodotRosettaRpc" Version="0.1.0" />
</ItemGroup>
Project setup
Your project also needs:
A .NET-enabled Godot editor/export templates already set up. C# support is built into Godot itself, but since it doesn't yet support GDExtension, it requires a Mono-specific binary.
protoc's generated message + RPC glue sources on the compile path. An SDK-style.csprojcan glob-include every.csfile under the project directory by default. Simply pointprotoc --csharp_out=...and--rosetta-rpc_out=lang=csharp:...somewhere under your project root and no further wiring is needed. See example/generate.py for a working configuration.
Implementing an RPC service
Each service Foo {} in your .proto file generates a C# interface IFoo
with one method per RPC. Implement it anywhere in
your codebase — the generated interface doesn't assume any particular
namespace or location:
public class BuzzerImpl : IBuzzer
{
private readonly GeneratedServiceFactory _factory;
public BuzzerImpl(GeneratedServiceFactory factory) => _factory = factory;
public PingResponse Ping(PingRequest request)
{
var clock = _factory.Clock();
var currentTime = clock.CurrentTime(new CurrentTimeRequest());
return new PingResponse { Message = $"pong: {request.Message} @ {currentTime.Millis}ms" };
}
}
A method reports failure by throwing an exception (of any type). The exception will be propagated as an RpcException
with RpcErrorCode.Application (see Error handling).
Register an RPC service
Every service implemented in C# must be linked through a single
public class AppServiceImplementations in namespace RpcImpls,
implementing the generated ServiceImplementations interface. That fixed,
well-known location is what lets the generated Bootstrap.cs find your
implementations without depending on your project's own namespace layout:
namespace RpcImpls;
public class AppServiceImplementations : ServiceImplementations
{
public IBuzzer? Buzzer(GeneratedServiceFactory factory) => new BuzzerImpl(factory);
}
Only override the services implemented in C# — every other method defaults
to returning null, meaning "not implemented in this language."
Call an RPC service
From any Godot Node, build an RpcClient with
GodotSupport.MakeRpcClient(this), wrap it in the generated
GeneratedServiceFactory, then call through the factory:
[GlobalClass]
public partial class MyNode : Node2D
{
public override void _Ready()
{
var services = new GeneratedServiceFactory(GodotSupport.MakeRpcClient(this));
// Without error handling.
var response = services.Buzzer().Ping(new PingRequest { Message = "hello" });
GD.Print(response.Message);
// With error handling.
try
{
var response = services.Buzzer().Ping(new PingRequest { Message = "hello" });
GD.Print(response.Message);
}
catch (RpcException e)
{
GD.PrintErr($"Ping failed ({e.Code}): {e.Message}");
}
}
}
To call one service from another's implementation, reuse the
GeneratedServiceFactory passed into your constructor (see above) instead of
building a new one.
Error handling
RpcClient.Call throws RpcException when a call fails. RpcException.Code
is an RpcErrorCode:
UnknownService/UnknownMethod— no service/method is registered for the id the client called with.Decode— the request or response protobuf failed to decode.Application— the service implementation itself failed: it threw, or an otherwise-uncaught exception was caught on its behalf byGodotSupport.DispatchBytes.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net8.0
- GodotSharp (>= 4.6.3)
- Google.Protobuf (>= 3.32.1)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.