Interface IRpcCommandSerializer<T>
Interface that must be implemented by a burst-compatible struct to serialize/deserialize the
specified T
type.
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 IRpc
Namespace: Unity.NetCode
Assembly: Unity.NetCode.dll
Syntax
public interface IRpcCommandSerializer<T> where T : struct, IComponentData
Type Parameters
Name | Description |
---|---|
T | Component type to serialize |
Methods
CompileExecute()
Invoked when the rpc is registered to the Rpc
Declaration
PortableFunctionPointer<RpcExecutor.ExecuteDelegate> CompileExecute()
Returns
Type | Description |
---|---|
Portable |
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. |
Deserialize(ref DataStreamReader, in RpcDeserializerState, ref T)
Method called by the Rpcreader
to the output data
.
The deserialization code is automatically generated when your struct implements the
IRpc
Declaration
void Deserialize(ref DataStreamReader reader, in RpcDeserializerState state, ref T data)
Parameters
Type | Name | Description |
---|---|---|
Data |
reader | Data reader |
Rpc |
state | Serializer state |
T | data | data to read into |
Serialize(ref DataStreamWriter, in RpcSerializerState, in T)
Method called by the Rpc
Declaration
void Serialize(ref DataStreamWriter writer, in RpcSerializerState state, in T data)
Parameters
Type | Name | Description |
---|---|---|
Data |
writer | Data writer |
Rpc |
state | Serializer state |
T | data | data to serialize |