Skip to content

Commit

Permalink
perf: rpc messages are now value types (#997)
Browse files Browse the repository at this point in the history
  • Loading branch information
paulpach authored and miwarnec committed Jul 30, 2019
1 parent f9ff443 commit b5b2f3e
Showing 1 changed file with 52 additions and 7 deletions.
59 changes: 52 additions & 7 deletions Assets/Mirror/Runtime/Messages.cs
Original file line number Diff line number Diff line change
Expand Up @@ -202,8 +202,7 @@ public void Serialize(NetworkWriter writer)
#endregion

#region System Messages requried for code gen path
// remote calls like Rpc/Cmd/SyncEvent all use the same message type
class RemoteCallMessage : MessageBase
struct CommandMessage : IMessageBase
{
public uint netId;
public int componentIndex;
Expand All @@ -212,15 +211,15 @@ class RemoteCallMessage : MessageBase
// -> ArraySegment to avoid unnecessary allocations
public ArraySegment<byte> payload;

public override void Deserialize(NetworkReader reader)
public void Deserialize(NetworkReader reader)
{
netId = reader.ReadPackedUInt32();
componentIndex = (int)reader.ReadPackedUInt32();
functionHash = reader.ReadInt32(); // hash is always 4 full bytes, WritePackedInt would send 1 extra byte here
payload = reader.ReadBytesAndSizeSegment();
}

public override void Serialize(NetworkWriter writer)
public void Serialize(NetworkWriter writer)
{
writer.WritePackedUInt32(netId);
writer.WritePackedUInt32((uint)componentIndex);
Expand All @@ -229,11 +228,57 @@ public override void Serialize(NetworkWriter writer)
}
}

class CommandMessage : RemoteCallMessage {}
struct RpcMessage : IMessageBase
{
public uint netId;
public int componentIndex;
public int functionHash;
// the parameters for the Cmd function
// -> ArraySegment to avoid unnecessary allocations
public ArraySegment<byte> payload;

class RpcMessage : RemoteCallMessage {}
public void Deserialize(NetworkReader reader)
{
netId = reader.ReadPackedUInt32();
componentIndex = (int)reader.ReadPackedUInt32();
functionHash = reader.ReadInt32(); // hash is always 4 full bytes, WritePackedInt would send 1 extra byte here
payload = reader.ReadBytesAndSizeSegment();
}

class SyncEventMessage : RemoteCallMessage {}
public void Serialize(NetworkWriter writer)
{
writer.WritePackedUInt32(netId);
writer.WritePackedUInt32((uint)componentIndex);
writer.WriteInt32(functionHash);
writer.WriteBytesAndSizeSegment(payload);
}
}

struct SyncEventMessage : IMessageBase
{
public uint netId;
public int componentIndex;
public int functionHash;
// the parameters for the Cmd function
// -> ArraySegment to avoid unnecessary allocations
public ArraySegment<byte> payload;

public void Deserialize(NetworkReader reader)
{
netId = reader.ReadPackedUInt32();
componentIndex = (int)reader.ReadPackedUInt32();
functionHash = reader.ReadInt32(); // hash is always 4 full bytes, WritePackedInt would send 1 extra byte here
payload = reader.ReadBytesAndSizeSegment();
}

public void Serialize(NetworkWriter writer)
{
writer.WritePackedUInt32(netId);
writer.WritePackedUInt32((uint)componentIndex);
writer.WriteInt32(functionHash);
writer.WriteBytesAndSizeSegment(payload);
}
}
#endregion

#region Internal System Messages
Expand Down

0 comments on commit b5b2f3e

Please sign in to comment.