Esempio n. 1
0
        /// <summary>EncodeBody
        /// </summary>
        public override byte[] EncodeBody(ClusterConfiguration configuration)
        {
            var groupNameBuffer = EndecodeUtil.EncodeGroupName(GroupName, configuration.Charset);
            var fileIdBuffer    = EndecodeUtil.EncodeString(FileId, configuration.Charset);

            //var length = Consts.FDFS_GROUP_NAME_MAX_LEN + fileIdBuffer.Length;
            return(ByteUtil.Combine(groupNameBuffer, fileIdBuffer));
        }
        /// <summary>EncodeBody
        /// </summary>
        public override byte[] EncodeBody(ClusterConfiguration configuration)
        {
            var groupNameBuffer = EndecodeUtil.EncodeGroupName(GroupName, configuration.Charset);
            //文件偏移量
            var offsetBuffer = EndecodeUtil.EncodeLong(Offset);
            //下载文件的大小,全部下载用0
            var byteSizeBuffer = EndecodeUtil.EncodeLong(ByteSize);
            //文件FileId数组
            var fileIdBuffer = EndecodeUtil.EncodeString(FileId, configuration.Charset);

            //long length = Consts.FDFS_PROTO_PKG_LEN_SIZE + Consts.FDFS_PROTO_PKG_LEN_SIZE + Consts.FDFS_GROUP_NAME_MAX_LEN + FileId.Length;

            return(ByteUtil.Combine(offsetBuffer, byteSizeBuffer, groupNameBuffer, fileIdBuffer));
        }
Esempio n. 3
0
        private byte[] CreateMetaDataBuffer(FastDFSOption option, IDictionary <string, string> metaData)
        {
            List <byte> metaDataBuffer = new List <byte>();

            foreach (KeyValuePair <string, string> p in metaData)
            {
                // insert a separater if this is not the first meta data item.
                if (metaDataBuffer.Count != 0)
                {
                    metaDataBuffer.Add(Consts.METADATA_PAIR_SEPARATER);
                }

                metaDataBuffer.AddRange(EndecodeUtil.EncodeString(p.Key, option.Charset));
                metaDataBuffer.Add(Consts.METADATA_KEY_VALUE_SEPARATOR);
                metaDataBuffer.AddRange(EndecodeUtil.EncodeString(p.Value, option.Charset));
            }
            return(metaDataBuffer.ToArray());
        }
Esempio n. 4
0
        ///// <summary>是否流请求
        ///// </summary>
        //public override bool StreamRequest => true;

        /// <summary>EncodeBody
        /// </summary>
        public override byte[] EncodeBody(ClusterConfiguration configuration)
        {
            //文件名长度数组
            var masterFileIdLenBuffer = EndecodeUtil.EncodeLong((long)MasterFileId.Length);
            //文件长度数组
            var fileSizeBuffer = EndecodeUtil.EncodeLong(InputStream.Length);

            //从文件前缀名数据
            var prefixBuffer = EndecodeUtil.EncodePrefix(Prefix, configuration.Charset);
            var extBuffer    = EndecodeUtil.EncodeFileExt(FileExt, configuration.Charset);
            //主文件Id
            var masterFileIdBuffer = EndecodeUtil.EncodeString(MasterFileId, configuration.Charset);


            //2个长度,主文件FileId数组长度,文件长度
            //long length = 2 * Consts.FDFS_PROTO_PKG_LEN_SIZE + Consts.FDFS_FILE_PREFIX_MAX_LEN + Consts.FDFS_FILE_EXT_NAME_MAX_LEN + masterFileIdBuffer.Length;

            return(ByteUtil.Combine(masterFileIdLenBuffer, fileSizeBuffer, prefixBuffer, extBuffer, masterFileIdBuffer));

            //文件内容
            //Array.Copy(ContentBytes, 0, bodyBuffer, offset, ContentBytes.Length);
        }
Esempio n. 5
0
        /// <summary>EncodeBody
        /// </summary>
        public override byte[] EncodeBody(FastDFSOption option)
        {
            string optionString = (Option == MetaDataOption.Overwrite) ? "O" : "M";
            var    optionBuffer = EndecodeUtil.EncodeString(optionString, option.Charset);

            var groupNameBuffer = EndecodeUtil.EncodeGroupName(GroupName, option.Charset);


            var fileIdBuffer   = ByteUtil.StringToByte(FileId, option.Charset);
            var metaDataBuffer = CreateMetaDataBuffer(option, MetaData);

            var fileIdLengthBuffer = ByteUtil.LongToBuffer(fileIdBuffer.Length);
            var metaDataSizeBuffer = ByteUtil.LongToBuffer(metaDataBuffer.Length);

            //int length = Consts.FDFS_PROTO_PKG_LEN_SIZE +  // filename length
            //             Consts.FDFS_PROTO_PKG_LEN_SIZE +  // metadata size
            //             1 +  // operation flag
            //             Consts.FDFS_GROUP_NAME_MAX_LEN +  // group name
            //             fileIdBuffer.Length +  // file name
            //             metaDataBuffer.Length;            // metadata


            return(ByteUtil.Combine(fileIdLengthBuffer, metaDataSizeBuffer, optionBuffer, groupNameBuffer, fileIdBuffer, metaDataBuffer));
        }