Interface IRpcCommandSerializer<T>
Interface that must be implemented by a burst-compatible struct to serialize/deserialize the
specified
A common pattern is to make the struct declaring the rpc to also implement the serialize/deserialize interface. For example:
struct MyRpc : IComponentData, IRpcCommandSerializer{MyRpc}
{
public void Serialize(ref DataStreamWriter writer, in RpcSerializerState state, in MyRpc data)
{ ... }
public void Deserialize(ref DataStreamReader reader, in RpcDeserializerState state, ref MyRpc data)
{ ... }
PortableFunctionPointer{RpcExecutor.ExecuteDelegate} CompileExecute()
{ ... }
}
When declaring an rpc using the IRpcCommand interface, it is not necessary to implement the
IRpcCommandSerializer
interface yourself; the code-generation will automatically create a struct implementing the interface
and all necessary boilerplate code.
Namespace: Unity.NetCode
Syntax
public interface IRpcCommandSerializer<T>
where T : struct, IComponentData
Type Parameters
Name | Description |
---|---|
T |
Methods
CompileExecute()
Invoked when the rpc is registered to the RpcSystem at runtime. Should return a valid burst-compatible function pointer of a static method that will be called after the rpc has been deserialized to actually "execute" the command. By declaring rpcs using IRpcCommand, this method is automatically generated. See also RpcExecutor for further information on how to use it to implement your custom execute method.
Declaration
PortableFunctionPointer<RpcExecutor.ExecuteDelegate> CompileExecute()
Returns
Type | Description |
---|---|
PortableFunctionPointer<RpcExecutor.ExecuteDelegate> |
Deserialize(ref DataStreamReader, in RpcDeserializerState, ref T)
Method called by the RpcSystem when an rpc is dequeued from the
IncomingRpcDataStreamBuffer. Copies the data from the
reader
to the output data
.
The deserialization code is automatically generated when your struct implements the
IRpcCommand interface.
You must implement this method yourself when you opt-in for manual serialization.
Declaration
void Deserialize(ref DataStreamReader reader, in RpcDeserializerState state, ref T data)
Parameters
Type | Name | Description |
---|---|---|
DataStreamReader | reader | |
RpcDeserializerState | state | |
T | data |
Serialize(ref DataStreamWriter, in RpcSerializerState, in T)
Method called by the RpcSystem when an rpc is dequeued from the OutgoingRpcDataStreamBuffer (to be sent over the network). The serialization code is automatically generated when your struct implements the IRpcCommand interface. You must implement this method yourself when you opt-in for manual serialization.
Declaration
void Serialize(ref DataStreamWriter writer, in RpcSerializerState state, in T data)
Parameters
Type | Name | Description |
---|---|---|
DataStreamWriter | writer | |
RpcSerializerState | state | |
T | data |