//========================= protected T getData <T> () { //using (MemoryStream stream = new MemoryStream(byts)) //{ //DebugTool.Log("getData() :: ProtoBuf.Serializer.Deserialize() :: 1"); //var obj = RuntimeTypeModel.Default.Deserialize(stream, null, typeof(T)); //T rsp = ProtoBuf.Serializer.Deserialize<T>(stream); //------------------------ T rsp = default(T); try { rsp = ProtoTool.DeSerialize_mbile <T> (this.byts, ProtoTool.proto); //T rsp = ProtoBuf.Serializer.DeserializeWithLengthPrefix<T>(stream, ProtoBuf.PrefixStyle.Base128); //T rsp = ProtoBuf.Serializer.NonGeneric.Deserialize(typeof(T),stream); //DebugTool.Log("getData() :: ProtoBuf.Serializer.Deserialize() :: 2"); //DebugTool.LogYellow ("<<< 接收 pb : " + rsp.GetType ().FullName); return(rsp); } catch (Exception e) { DebugTool.LogError("DeSerialize_mbile:: " + e.Message); } //catch (EndOfStreamException e) //{ // DebugTool.LogError("EndOfStream Error" + e.Message); // //Nothing new on the stream //} //catch (ObjectDisposedException e) //{ // DebugTool.LogError("ObjectDisposed Error" + e.Message); //} //catch (IOException e) //{ // DebugTool.LogError("IOError" + e.Message); //} return(rsp); //default(T); //------------------------ //}// end using stream }
public void Send <T> (short cmd, T data, bool locked = false) { // queue_LogError.Enqueue ("[TCP] <color=red>Send</color><" + typeof(T) + "> , cmd: " + cmd); if (reconnect_Lock) { return; } if (m_Socket != null) { if (m_Socket.Connected) { var rqst = data; byte[] pb_stream = ProtoTool.Serialize_mobile <T> (rqst, ProtoTool.proto); //protobuf 也无需再次转为BigEndian byte[] buffer_snd = this.Packet(cmd, pb_stream); // queue_LogError.Enqueue("[TCP] ======= "); // foreach(var item in buffer_snd){ // queue_LogError.Enqueue("[TCP] 发:" + item); // } try { int sended_Size = 0; do { sended_Size += m_Socket.Send(buffer_snd, sended_Size, buffer_snd.Length - sended_Size, SocketFlags.None); } while (sended_Size < buffer_snd.Length); } catch (Exception e) { queue_LogError.Enqueue("Send :: Serialize_mobile:: " + e.Message); } } else { Reconnection(); } } //------------------------------------------------------------------ }