Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implemented parsing of ROOM_DATA_BYTES #228

Merged
merged 1 commit into from
Jul 3, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 19 additions & 9 deletions Assets/Colyseus/Runtime/Colyseus/Room/ColyseusRoom.cs
Original file line number Diff line number Diff line change
Expand Up @@ -503,7 +503,7 @@ protected async void ParseMessage(byte[] bytes)
{
Patch(bytes, 1);
}
else if (code == ColyseusProtocol.ROOM_DATA)
else if (code == ColyseusProtocol.ROOM_DATA || ColyseusProtocol.ROOM_DATA_BYTES)
{
IColyseusMessageHandler handler = null;
object type;
Expand All @@ -523,14 +523,24 @@ protected async void ParseMessage(byte[] bytes)

if (handler != null)
{
//
// MsgPack deserialization can be optimized:
// https://github.com/deniszykov/msgpack-unity3d/issues/23
//
object message = bytes.Length > it.Offset
? MsgPack.Deserialize(handler.Type,
new MemoryStream(bytes, it.Offset, bytes.Length - it.Offset, false))
: null;
object message = null;

if ( code == ColyseusProtocol.ROOM_DATA )
{
//
// MsgPack deserialization can be optimized:
// https://github.com/deniszykov/msgpack-unity3d/issues/23
//
message = bytes.Length > it.Offset
? MsgPack.Deserialize(handler.Type,
new MemoryStream(bytes, it.Offset, bytes.Length - it.Offset, false))
: null;
}
else if ( code == ColyseusProtocol.ROOM_DATA_BYTES )
{
message = new byte[bytes.Length - it.Offset];
Buffer.BlockCopy(bytes, it.Offset, (byte[])message, 0, bytes.Length - it.Offset);
}

handler.Invoke(message);
}
Expand Down