Ejemplo n.º 1
0
        public FDFSHeader(Stream stream)
        {
            int count = Consts.FDFS_PROTO_PKG_LEN_SIZE + 2;

            byte[] headerBuffer = new byte[count];
            var    offset       = 0;

            while (count > 0)
            {
                var readCount = stream.Read(headerBuffer, offset, count);
                if (readCount <= 0)
                {
                    throw new FDFSException("Get Response Header Error,readCount <= 0");
                }

                offset += readCount;
                count  -= readCount;
            }


            //int bytesRead = stream.Read(headerBuffer, 0, headerBuffer.Length);

            //if (bytesRead == 0)
            //    throw new FDFSException("Init Header Exeption : Cann't Read Stream");

            _length  = FDFSUtil.BufferToLong(headerBuffer, 0);
            _command = headerBuffer[Consts.FDFS_PROTO_PKG_LEN_SIZE];
            _status  = headerBuffer[Consts.FDFS_PROTO_PKG_LEN_SIZE + 1];
        }
Ejemplo n.º 2
0
 public Response(byte[] responseByte)
 {
     byte[] groupNameBuffer = new byte[Consts.FDFS_GROUP_NAME_MAX_LEN];
     Array.Copy(responseByte, groupNameBuffer, Consts.FDFS_GROUP_NAME_MAX_LEN);
     GroupName = FDFSUtil.ByteToString(groupNameBuffer).TrimEnd('\0');
     byte[] ipAddressBuffer = new byte[Consts.IP_ADDRESS_SIZE - 1];
     Array.Copy(responseByte, Consts.FDFS_GROUP_NAME_MAX_LEN, ipAddressBuffer, 0, Consts.IP_ADDRESS_SIZE - 1);
     IPStr = new string(FDFSConfig.Charset.GetChars(ipAddressBuffer)).TrimEnd('\0');
     byte[] portBuffer = new byte[Consts.FDFS_PROTO_PKG_LEN_SIZE];
     Array.Copy(responseByte, Consts.FDFS_GROUP_NAME_MAX_LEN + Consts.IP_ADDRESS_SIZE - 1,
                portBuffer, 0, Consts.FDFS_PROTO_PKG_LEN_SIZE);
     Port = (int)FDFSUtil.BufferToLong(portBuffer, 0);
 }
Ejemplo n.º 3
0
        public FDFSFileInfo(byte[] responseByte)
        {
            byte[] fileSizeBuffer   = new byte[Consts.FDFS_PROTO_PKG_LEN_SIZE];
            byte[] createTimeBuffer = new byte[Consts.FDFS_PROTO_PKG_LEN_SIZE];
            byte[] crcBuffer        = new byte[Consts.FDFS_PROTO_PKG_LEN_SIZE];

            Array.Copy(responseByte, 0, fileSizeBuffer, 0, fileSizeBuffer.Length);
            Array.Copy(responseByte, Consts.FDFS_PROTO_PKG_LEN_SIZE, createTimeBuffer, 0, createTimeBuffer.Length);
            Array.Copy(responseByte, Consts.FDFS_PROTO_PKG_LEN_SIZE + Consts.FDFS_PROTO_PKG_LEN_SIZE, crcBuffer, 0, crcBuffer.Length);

            FileSize   = FDFSUtil.BufferToLong(responseByte, 0);
            CreateTime = new System.DateTime(1970, 1, 1).AddSeconds(FDFSUtil.BufferToLong(responseByte, Consts.FDFS_PROTO_PKG_LEN_SIZE));

            Crc32 = FDFSUtil.BufferToLong(responseByte, Consts.FDFS_PROTO_PKG_LEN_SIZE + Consts.FDFS_PROTO_PKG_LEN_SIZE);
        }