public static Message ToMessage(MessageClass @class, Proto.ISerializerable m) { var index = 0; if (MessageHandleTypes.GetTypeIndex(m.GetType(), out index)) { using (var mem = new MemoryStream()) { using (var bw = new BinaryWriter(mem)) { m.ToBinary(bw); } return(new Message(@class, index, mem.ToArray())); } } return(null); }
private void SendRequest(Proto.ISerializerable request, int requestIndex) { var index = 0; if (MessageHandleTypes.GetTypeIndex(request.GetType(), out index)) { using (var mem = new MemoryStream()) { using (var bw = new BinaryWriter(mem)) { bw.Write(requestIndex); request.ToBinary(bw); #if NETDEBUG Debug.Log(request.GetType() + "-->" + JsonTool.Serialize(request)); #endif } var result = new Message(MessageClass.Request, index, mem.ToArray()); SendMessage(result); } } }