public TransferCommandInfo GetCommandInfo(byte[] readBuffer, int offset, int length, out int left) { left = 0; if ((readBuffer.Length - length) >= 4) { UpLoadOP dop = (UpLoadOP)((readBuffer[offset] * 0x100) + readBuffer[offset + 1]); if (!Enum.IsDefined(typeof(UpLoadOP), dop)) { return(null); } left = 4; int count = (readBuffer[offset + 2] * 0x100) + readBuffer[offset + 3]; byte[] dst = new byte[count]; Buffer.BlockCopy(readBuffer, left, dst, 0, count); switch (dop) { case UpLoadOP.DoUpLoad: return(new TransferCommandInfo(UpLoadOP.DoUpLoad.ToString(), dst)); case UpLoadOP.DoExists: return(new TransferCommandInfo(UpLoadOP.DoExists.ToString(), dst)); //case UpLoadOP.DoEnd: // return new TransferCommandInfo(UpLoadOP.DoEnd.ToString(), dst); case UpLoadOP.DoStop: return(new TransferCommandInfo(UpLoadOP.DoStop.ToString(), dst)); } } return(null); }
internal void SendData(UpLoadOP opCode, byte[] data, int offset, int length) { byte[] dst = new byte[length + 4]; dst[0] = (byte)((int)opCode / 256); dst[1] = (byte)((int)opCode % 256); dst[2] = (byte)(data.Length / 256); dst[3] = (byte)(data.Length % 256); Buffer.BlockCopy(data, offset, dst, 4, length); this.Session.Send(dst, 0, dst.Length); }
protected override BinaryRequestInfo ResolveRequestInfo(ArraySegment <byte> header, byte[] bodyBuffer, int offset, int length) { int num = header.Array[0]; if (num == 0) { UpLoadOP dop = (UpLoadOP)(header.Array[1] * 256) + header.Array[2]; return(new BinaryRequestInfo(dop.ToString(), bodyBuffer.CloneRange <byte>(offset, length))); } return(null); }