/// <summary>EncodeBody
        /// </summary>
        public override byte[] EncodeBody(FastDFSOption option)
        {
            var bodyBuffer = EndecodeUtil.EncodeGroupName(GroupName, option.Charset);

            //Header = new FDFSHeader(Consts.FDFS_GROUP_NAME_MAX_LEN, Consts.TRACKER_PROTO_CMD_SERVER_LIST_STORAGE, 0);
            return(bodyBuffer);
        }
        /// <summary>LoadContent
        /// </summary>
        public override void LoadContent(ClusterConfiguration configuration, byte[] data)
        {
            int bytesRead = 0;

            byte[] groupNameBuffer = new byte[Consts.FDFS_GROUP_NAME_MAX_LEN];
            Array.Copy(data, bytesRead, groupNameBuffer, 0, Consts.FDFS_GROUP_NAME_MAX_LEN);
            GroupName = EndecodeUtil.DecodeString(groupNameBuffer, configuration.Charset);
            //Util.ByteToString(option.Charset, groupNameBuffer).TrimEnd('\0');
            bytesRead += Consts.FDFS_GROUP_NAME_MAX_LEN;

            byte[] ipAddressBuffer = new byte[Consts.IP_ADDRESS_SIZE - 1];
            Array.Copy(data, bytesRead, ipAddressBuffer, 0, Consts.IP_ADDRESS_SIZE - 1);
            IPAddresses.Add(EndecodeUtil.DecodeString(ipAddressBuffer, configuration.Charset));
            //IPAddresses.Add(new string(option.Charset.GetChars(ipAddressBuffer)).TrimEnd('\0'));
            bytesRead += Consts.IP_ADDRESS_SIZE - 1;

            byte[] portBuffer = new byte[Consts.FDFS_PROTO_PKG_LEN_SIZE];
            Array.Copy(data, bytesRead, portBuffer, 0, Consts.FDFS_PROTO_PKG_LEN_SIZE);
            Port       = (int)ByteUtil.BufferToLong(portBuffer, 0);
            bytesRead += Consts.FDFS_PROTO_PKG_LEN_SIZE;

            while (data.Length - bytesRead >= Consts.IP_ADDRESS_SIZE - 1)
            {
                ipAddressBuffer = new byte[Consts.IP_ADDRESS_SIZE - 1];
                Array.Copy(data, bytesRead, ipAddressBuffer, 0, Consts.IP_ADDRESS_SIZE - 1);
                IPAddresses.Add(EndecodeUtil.DecodeString(ipAddressBuffer, configuration.Charset));
                // IPAddresses.Add(new string(option.Charset.GetChars(ipAddressBuffer)).TrimEnd('\0'));
                bytesRead += Consts.IP_ADDRESS_SIZE - 1;
            }
        }
        /// <summary>EncodeBody
        /// </summary>
        public override byte[] EncodeBody(ClusterConfiguration configuration)
        {
            var bodyBuffer = EndecodeUtil.EncodeGroupName(GroupName, configuration.Charset);

            //Header = new FDFSHeader(Consts.FDFS_GROUP_NAME_MAX_LEN, Consts.TRACKER_PROTO_CMD_SERVER_LIST_ONE_GROUP, 0);
            return(bodyBuffer);
        }
        /// <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>LoadContent
 /// </summary>
 public override void LoadContent(ClusterConfiguration configuration, byte[] data)
 {
     if (data.Length != Consts.FDFS_GROUP_INFO_SIZE)
     {
         throw new ArgumentException($"返回数据长度:{data.Length},不是有效的GroupInfo数据长度.");
     }
     GroupInfo = EndecodeUtil.DecodeGroupInfo(data, configuration.Charset);
 }
Exemple #6
0
        /// <summary>EncodeBody
        /// </summary>
        public override byte[] EncodeBody(ClusterConfiguration configuration)
        {
            //消息体长度为group name的最大长度,16

            var bodyBuffer = EndecodeUtil.EncodeGroupName(GropName, configuration.Charset);

            //Header = new FDFSHeader(Consts.FDFS_GROUP_NAME_MAX_LEN, Consts.TRACKER_PROTO_CMD_SERVICE_QUERY_STORE_WITH_GROUP_ONE, 0);
            return(bodyBuffer);
        }
Exemple #7
0
        /// <summary>LoadContent
        /// </summary>
        public override void LoadContent(FastDFSOption option, byte[] data)
        {
            var span          = data.AsSpan();
            var groupNameSpan = span.Slice(0, Consts.FDFS_GROUP_NAME_MAX_LEN);

            GroupName = EndecodeUtil.DecodeString(groupNameSpan.ToArray(), option.Charset);

            var fileNameSpan = span.Slice(Consts.FDFS_GROUP_NAME_MAX_LEN, data.Length - Consts.FDFS_GROUP_NAME_MAX_LEN);

            FileId = EndecodeUtil.DecodeString(fileNameSpan.ToArray(), option.Charset);
        }
        /// <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));
        }
        ///// <summary>是否流请求
        ///// </summary>
        //public override bool StreamRequest => true;

        /// <summary>EncodeBody
        /// </summary>
        public override byte[] EncodeBody(ClusterConfiguration configuration)
        {
            var fileSizeBuffer = ByteUtil.LongToBuffer(InputStream.Length);
            var extBuffer      = EndecodeUtil.EncodeFileExt(FileExt, configuration.Charset);

            /*long lenth = 1 + Consts.FDFS_PROTO_PKG_LEN_SIZE + Consts.FDFS_FILE_EXT_NAME_MAX_LEN;*/

            var bodyBuffer = new List <byte>
            {
                StorePathIndex
            };

            bodyBuffer.AddRange(fileSizeBuffer);
            bodyBuffer.AddRange(extBuffer);
            return(bodyBuffer.ToArray());
        }
Exemple #10
0
        /// <summary>LoadContent
        /// </summary>
        public override void LoadContent(FastDFSOption option, byte[] data)
        {
            byte[] groupNameBuffer = new byte[Consts.FDFS_GROUP_NAME_MAX_LEN];
            Array.Copy(data, groupNameBuffer, Consts.FDFS_GROUP_NAME_MAX_LEN);
            GroupName = EndecodeUtil.DecodeString(groupNameBuffer);

            byte[] ipAddressBuffer = new byte[Consts.IP_ADDRESS_SIZE - 1];
            Array.Copy(data, Consts.FDFS_GROUP_NAME_MAX_LEN, ipAddressBuffer, 0, Consts.IP_ADDRESS_SIZE - 1);
            IPAddress = EndecodeUtil.DecodeString(ipAddressBuffer);
            //new string(option.Charset.GetChars(ipAddressBuffer)).TrimEnd('\0');

            byte[] portBuffer = new byte[Consts.FDFS_PROTO_PKG_LEN_SIZE];
            Array.Copy(data, Consts.FDFS_GROUP_NAME_MAX_LEN + Consts.IP_ADDRESS_SIZE - 1,
                       portBuffer, 0, Consts.FDFS_PROTO_PKG_LEN_SIZE);

            Port = (int)ByteUtil.BufferToLong(portBuffer, 0);
        }
Exemple #11
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());
        }
Exemple #12
0
        /// <summary>LoadContent
        /// </summary>
        public override void LoadContent(ClusterConfiguration configuration, byte[] data)
        {
            if (data.Length % Consts.FDFS_STORAGE_INFO_SIZE != 0)
            {
                throw new ArgumentException("返回数据长度不正确,不是'FDFS_STORAGE_INFO_SIZE' 的整数倍.");
            }
            var count = data.Length / Consts.FDFS_STORAGE_INFO_SIZE;

            var dataSpan = data.AsSpan();

            for (int i = 0; i < count; i++)
            {
                //var buffer = new byte[Consts.FDFS_STORAGE_INFO_SIZE];
                //Array.Copy(data, i * Consts.FDFS_STORAGE_INFO_SIZE, buffer, 0, buffer.Length);
                var bufferSpan = dataSpan.Slice(i * Consts.FDFS_STORAGE_INFO_SIZE, Consts.FDFS_STORAGE_INFO_SIZE);

                var storageInfo = EndecodeUtil.DecodeStorageInfo(bufferSpan.ToArray(), configuration.Charset);
                StorageInfos.Add(storageInfo);
            }
        }
        /// <summary>LoadContent
        /// </summary>
        public override void LoadContent(FastDFSOption option, byte[] data)
        {
            if (data.Length % Consts.FDFS_GROUP_INFO_SIZE != 0)
            {
                throw new ArgumentException("返回数据长度不正确,不是'FDFS_GROUP_INFO_SIZE' 的整数倍.");
            }
            var count = data.Length / Consts.FDFS_GROUP_INFO_SIZE;

            var dataSpan = data.AsSpan();

            for (int i = 0; i < count; i++)
            {
                //var buffer = new byte[Consts.FDFS_GROUP_INFO_SIZE];
                //Array.Copy(data, i * Consts.FDFS_GROUP_INFO_SIZE, buffer, 0, buffer.Length);

                var bufferSpan = dataSpan.Slice(i * Consts.FDFS_GROUP_INFO_SIZE, Consts.FDFS_GROUP_INFO_SIZE);

                var groupInfo = EndecodeUtil.DecodeGroupInfo(bufferSpan.ToArray(), option.Charset);
                GroupInfos.Add(groupInfo);
            }
        }
Exemple #14
0
        ///// <summary>使用流传输
        ///// </summary>
        //public override bool StreamRequest => true;

        /// <summary>EncodeBody
        /// </summary>
        public override byte[] EncodeBody(FastDFSOption option)
        {
            //1.StorePathIndex

            //2.文件长度
            var fileSizeBuffer = EndecodeUtil.EncodeLong(InputStream.Length);

            //3.扩展名
            byte[] extBuffer = EndecodeUtil.EncodeFileExt(FileExt, option.Charset);
            //4.文件数据,这里不写入
            //int lenth = 1 + Consts.FDFS_PROTO_PKG_LEN_SIZE + Consts.FDFS_FILE_EXT_NAME_MAX_LEN;

            var bodyBuffer = new List <byte>
            {
                StorePathIndex
            };

            bodyBuffer.AddRange(fileSizeBuffer);
            bodyBuffer.AddRange(extBuffer);
            return(bodyBuffer.ToArray());
        }
Exemple #15
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);
        }
        ///// <summary>使用流传输
        ///// </summary>
        //public override bool StreamRequest => true;

        /// <summary>EncodeBody
        /// </summary>
        public override byte[] EncodeBody(ClusterConfiguration configuration)
        {
            //1.StorePathIndex

            //2.文件长度

            //var fileSizeBuffer = EndecodeUtil.EncodeLong(InputStream.Length);
            byte[] fileSizeBuffer;
            if (InputStream != null)
            {
                fileSizeBuffer = EndecodeUtil.EncodeLong(InputStream.Length);
            }
            else
            {
                fileSizeBuffer = EndecodeUtil.EncodeLong(Content.Length);
            }


            //3.扩展名
            byte[] extBuffer = EndecodeUtil.EncodeFileExt(FileExt, configuration.Charset);
            //4.文件数据,这里不写入
            //int lenth = 1 + Consts.FDFS_PROTO_PKG_LEN_SIZE + Consts.FDFS_FILE_EXT_NAME_MAX_LEN;

            var bodyBuffer = new List <byte>
            {
                StorePathIndex
            };

            bodyBuffer.AddRange(fileSizeBuffer);
            bodyBuffer.AddRange(extBuffer);
            if (InputStream == null && Content != null)
            {
                bodyBuffer.AddRange(Content);
            }

            return(bodyBuffer.ToArray());
        }
Exemple #17
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));
        }