void UpdateSendBuf() { lock (pb_send_) { while (pb_send_.Count > 0) { PBMsg pb = pb_send_.Dequeue(); SocketData sockData = NetworkManager.ConvertToSocketData(pb); _sendBuf.Write(sockData); } } }
// Lua发送协议 public void LuaSendProtoImp(int requestType, byte[] baseVO, OnSendOkCallBack onSendOK) { if (_conn == null || SocketConnectionState.Connected != _conn.State) { Debug.LogError("sock connect not working!"); return; } PBMsg pb = new PBMsg(); pb.handle_id_ = (short)requestType; pb.bytes = baseVO; lock (_conn.pb_send_) { _conn.pb_send_.Enqueue(pb); } onSendOK.Invoke(); }
public static SocketData ConvertToSocketData(PBMsg pb) { byte[] bytes = pb.bytes; SocketData sockData = new SocketData(); sockData.handleId = pb.handle_id_; sockData.version = VERSION; if (bytes != null) // 干掉了这个验证 ProtoBuf.Meta.RuntimeTypeModel.Default.CanSerialize (byteArray.data.GetType())) { using (var ms = new System.IO.MemoryStream()) { sockData.data = bytes; } } else { Debug.LogError("Can not serialize object to proto: " + pb.handle_id_.ToString()); }; return(sockData); }