v9.7.2018.0421   支持运行时修改DAL连接字符串
大石头 authored at 2018-04-21 14:00:47
1.11 KiB
X
using System.IO;
using NewLife.Queue.Utilities;

namespace NewLife.Queue.Storage
{
    public class ChunkFooter
    {
        public const int Size = 128;
        public readonly int ChunkDataTotalSize;

        public ChunkFooter(int chunkDataTotalSize)
        {
            Ensure.Nonnegative(chunkDataTotalSize, "chunkDataTotalSize");
            ChunkDataTotalSize = chunkDataTotalSize;
        }

        public byte[] AsByteArray()
        {
            var array = new byte[Size];
            using (var stream = new MemoryStream(array))
            {
                using (var writer = new BinaryWriter(stream))
                {
                    writer.Write(ChunkDataTotalSize);
                }
            }
            return array;
        }

        public static ChunkFooter FromStream(BinaryReader reader, Stream stream)
        {
            var chunkDataTotalSize = reader.ReadInt32();
            return new ChunkFooter(chunkDataTotalSize);
        }

        public override string ToString()
        {
            return string.Format("[ChunkDataTotalSize:{0}]", ChunkDataTotalSize);
        }
    }
}