public override void OnMessage(USocket us, ByteBuf bb) { bb.ReaderIndex(us.getProtocol().HeaderLen()); short cmd = bb.ReadShort(); byte[] bs = bb.GetRaw(); Statics.SetXor(bs, bb.ReaderIndex()); MemoryStream stream = new MemoryStream(bs, bb.ReaderIndex(), bb.ReadableBytes()); object obj = ProtoBuf.Serializer.NonGeneric.Deserialize(MessageQueueHandler.GetProtocolType(cmd), stream); FieldInfo success = obj.GetType().GetField("success"); if (success != null) { if ((bool)success.GetValue(obj) == true) { MessageQueueHandler.PushQueue(cmd, obj); } else { FieldInfo info = obj.GetType().GetField("info"); if (info != null) { Debug.LogWarning("下行出错, cmd=" + cmd + ", type=" + MessageQueueHandler.GetProtocolType(cmd).ToString()); MessageQueueHandler.PushError(info.GetValue(obj).ToString()); } } } }
public override void OnMessage(USocket us, ByteBuf bb) { Console.WriteLine("收到数据:"); bb.ReaderIndex(us.getProtocol().HeaderLen()); int cmd = bb.ReadShort(); Type t = null; MemoryStream stream = new MemoryStream(bb.GetRaw(), bb.ReaderIndex(), bb.ReadableBytes()); object response = ProtoBuf.Serializer.NonGeneric.Deserialize(t, stream); /** * Console.WriteLine (response.pid); * Console.WriteLine(response.info); * Console.WriteLine(response.success); */ }