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 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.
Assembly: Unity.NetCode.dll
Syntax
public interface IRpcCommandSerializer<T> where T : struct, IComponentData
Type Parameters
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 RpcExecutor for further information on how to use it to implement your
custom execute method.
Declaration
PortableFunctionPointer<RpcExecutor.ExecuteDelegate> CompileExecute()
Returns
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
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
Did you find this page useful? Please give it a rating:
Thanks for rating this page!
What kind of problem would you like to report?
Thanks for letting us know! This page has been marked for review based on your feedback.
If you have time, you can provide more information to help us fix the problem faster.
Provide more information
You've told us this page needs code samples. If you'd like to help us further, you could provide a code sample, or tell us about what kind of code sample you'd like to see:
You've told us there are code samples on this page which don't work. If you know how to fix it, or have something better we could use instead, please let us know:
You've told us there is information missing from this page. Please tell us more about what's missing:
You've told us there is incorrect information on this page. If you know what we should change to make it correct, please tell us:
You've told us this page has unclear or confusing information. Please tell us more about what you found unclear or confusing, or let us know how we could make it clearer:
You've told us there is a spelling or grammar error on this page. Please tell us what's wrong:
You've told us this page has a problem. Please tell us more about what's wrong:
Thank you for helping to make the Unity documentation better!
Your feedback has been submitted as a ticket for our documentation team to review.
We are not able to reply to every ticket submitted.