/// <summary> /// /// </summary> /// <param name="paramList"> /// 1,IPEndPoint IPEndPoint-->the storage IPEndPoint /// 2,string FileName /// 3,byte[] File bytes /// </param> /// <returns></returns> public override FDFSRequest GetRequest(params object[] paramList) { if (paramList.Length != 3) { throw new FDFSException("param count is wrong"); } IPEndPoint endPoint = (IPEndPoint)paramList[0]; string fileName = (string)paramList[1]; byte[] contentBuffer = (byte[])paramList[2]; APPEND_FILE result = new APPEND_FILE(); result.Connection = ConnectionManager.GetStorageConnection(endPoint); long length = Consts.FDFS_PROTO_PKG_LEN_SIZE + Consts.FDFS_PROTO_PKG_LEN_SIZE + fileName.Length + contentBuffer.Length; byte[] bodyBuffer = new byte[length]; byte[] fileNameLenBuffer = Util.LongToBuffer(fileName.Length); Array.Copy(fileNameLenBuffer, 0, bodyBuffer, 0, fileNameLenBuffer.Length); byte[] fileSizeBuffer = Util.LongToBuffer(contentBuffer.Length); Array.Copy(fileSizeBuffer, 0, bodyBuffer, Consts.FDFS_PROTO_PKG_LEN_SIZE, fileSizeBuffer.Length); byte[] fileNameBuffer = Util.StringToByte(fileName); Array.Copy(fileNameBuffer, 0, bodyBuffer, Consts.FDFS_PROTO_PKG_LEN_SIZE + Consts.FDFS_PROTO_PKG_LEN_SIZE, fileNameBuffer.Length); Array.Copy(contentBuffer, 0, bodyBuffer, Consts.FDFS_PROTO_PKG_LEN_SIZE + Consts.FDFS_PROTO_PKG_LEN_SIZE + fileNameBuffer.Length, contentBuffer.Length); result.Body = bodyBuffer; result.Header = new FDFSHeader(length, Consts.STORAGE_PROTO_CMD_APPEND_FILE, 0); return(result); }
public override FDFSRequest GetRequest(params object[] paramList) { if (paramList.Length != 3) { throw new FDFSException("param count is wrong"); } var endPoint = (IPEndPoint)paramList[0]; var fileName = (string)paramList[1]; var contentStream = (Stream)paramList[2]; var appendFile = new APPEND_FILE { ConnectionType = FDFSConnectionType.StorageConnection, EndPoint = endPoint }; var fileNameByteCount = Util.StringByteCount(fileName); int bodyBufferLen = 16 + fileNameByteCount; appendFile.SetBodyBuffer(bodyBufferLen); int offset = 0; Util.LongToBuffer(fileNameByteCount, appendFile.BodyBuffer, offset); offset += 8; Util.LongToBuffer(contentStream.Length, appendFile.BodyBuffer, offset); offset += 8; Util.StringToByte(fileName, appendFile.BodyBuffer, offset, fileNameByteCount); appendFile.BodyStream = contentStream; long length = bodyBufferLen + contentStream.Length; appendFile.Header = new FDFSHeader(length, FDFSConstants.STORAGE_PROTO_CMD_APPEND_FILE, 0); return(appendFile); }