⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 bytearraybuffer.cs

📁 破解的飞信源代码
💻 CS
字号:
namespace NCindy.Buffer
{
    using NCindy;
    using System;

    public class ByteArrayBuffer : AbstractBuffer
    {
        protected byte[] content;
        protected static readonly byte[] EMPTY_CONTENT = new byte[0];

        protected ByteArrayBuffer(int capacity) : base(0, capacity)
        {
            this.content = new byte[capacity];
        }

        protected ByteArrayBuffer(byte[] content, int offset, int capacity) : base(offset, capacity)
        {
            this.content = content;
        }

        public override IBuffer Compact()
        {
            base.CheckReadonly();
            Buffer.BlockCopy(this.content, base.GetIndex(0), this.content, base.GetIndex(0, 0), base.Remaining);
            base.Position = base.Remaining;
            base.Limit = this.Capacity;
            return this;
        }

        public override IBuffer Duplicate()
        {
            ByteArrayBuffer buffer = new DelegateReleaseBuffer(this, base.GetIndex(0, 0), this.Capacity);
            buffer.Limit = base.Limit;
            buffer.Position = base.Position;
            buffer.InternalMark(base.GetMark());
            buffer.ReadOnly = base.ReadOnly;
            return buffer;
        }

        public override byte[] GetInnerByteArray()
        {
            return this.content;
        }

        internal override byte InternalGet(int index)
        {
            return this.content[index];
        }

        internal override void InternalPut(int index, byte byteValue)
        {
            this.content[index] = byteValue;
        }

        protected override void InternalRelease()
        {
            this.content = EMPTY_CONTENT;
        }

        public override IBuffer Slice()
        {
            return new DelegateReleaseBuffer(this, base.GetIndex(0), base.Remaining);
        }

        public static ByteArrayBuffer Wrap(byte[] array)
        {
            return Wrap(array, 0, array.Length);
        }

        public static ByteArrayBuffer Wrap(byte[] array, int offset, int length)
        {
            AbstractBuffer.CheckBounds(offset, length, array.Length);
            ByteArrayBuffer buffer = new ByteArrayBuffer(array, 0, array.Length);
            buffer.Limit = offset + length;
            buffer.Position = offset;
            return buffer;
        }

        internal override byte[] InnerByteArray
        {
            get
            {
                return this.content;
            }
        }

        private class DelegateReleaseBuffer : ByteArrayBuffer
        {
            private readonly ByteArrayBuffer parentBuffer;

            public DelegateReleaseBuffer(ByteArrayBuffer buffer, int offset, int capacity) : base(buffer.content, offset, capacity)
            {
                this.parentBuffer = buffer;
            }

            public override void Release()
            {
                this.parentBuffer.Release();
            }

            public override bool Permanent
            {
                get
                {
                    return this.parentBuffer.Permanent;
                }
                set
                {
                    this.parentBuffer.Permanent = value;
                }
            }

            public override bool Released
            {
                get
                {
                    return this.parentBuffer.Released;
                }
            }
        }
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -