fix: pack works if message is boxed

This commit is contained in:
Paul Pacheco 2019-09-26 18:54:11 -05:00
parent 6dcea5ffd5
commit 55c9bb625a
2 changed files with 7 additions and 2 deletions

View File

@ -25,6 +25,11 @@ public static int GetId<T>() where T : IMessageBase
return typeof(T).FullName.GetStableHashCode() & 0xFFFF;
}
public static int GetId(Type type)
{
return type.FullName.GetStableHashCode() & 0xFFFF;
}
// pack message before sending
[EditorBrowsable(EditorBrowsableState.Never), Obsolete("Use Pack<T> instead")]
public static byte[] PackMessage(int msgType, MessageBase msg)
@ -54,7 +59,7 @@ public static byte[] Pack<T>(T message) where T : IMessageBase
try
{
// write message type
int msgType = GetId<T>();
int msgType = GetId(message.GetType());
writer.WriteUInt16((ushort)msgType);
// serialize message into writer

View File

@ -334,7 +334,7 @@ internal bool InvokeHandler(int msgType, NetworkReader reader)
/// <returns></returns>
public bool InvokeHandler<T>(T msg) where T : IMessageBase
{
int msgType = MessagePacker.GetId<T>();
int msgType = MessagePacker.GetId(msg.GetType());
byte[] data = MessagePacker.Pack(msg);
return InvokeHandler(msgType, new NetworkReader(data));
}