void Decode() { Assert.Equal("zab", _coder.Decode("abc")); Assert.Equal("012", _coder.Decode("123")); Assert.Equal("wxy", _coder.Decode("xyz")); Assert.Equal("яма", _coder.Decode("анб")); }
private void beginReceiveCallback(IAsyncResult ar) { StateObject state = (StateObject)ar.AsyncState; Socket socket = state.workSocket; try { int readLength = socket.EndReceive(ar); if (readLength > 0) { UnityEngine.Debug.Log("TCP Receive data length = " + readLength); var data = new byte[readLength]; Array.Copy(state.buffer, 0, data, 0, readLength); // 不处理粘包、分包等问题,在ICoder中处理 // 并且ICoder需要自己保留本次的数据 List <Protobuf> proto; if (coder.Decode(data, out proto)) { foreach (var v in proto) { afterReceiveProto(v); } } } // 继续接收 socket.BeginReceive(state.buffer, 0, StateObject.BufferSize, SocketFlags.None, beginReceiveCallback, state); } catch (SocketException ex) { UnityEngine.Debug.LogWarning("TCP.Receive failed :"); UnityEngine.Debug.LogException(ex); } }
void Decode() { Assert.Equal("zab", _coder.Decode("azy")); Assert.Equal("cba", _coder.Decode("xyz")); Assert.Equal("АЯ", _coder.Decode("ЯА")); }
private static string Decrypt(ICoder coder, string inputString) { return(coder.Decode(inputString)); }
private void decode(string source, ICoder coder) { _source = coder.Decode(source); }