Пример #1
0
        public void RemoveRangeFromStart(int start, int length)
        {
            var moveLength = this.Length - length;
            var tempBuffer = new byte[moveLength];
            var moveSpan   = this.innerBuffer.AsSpan(start + length, moveLength);

            MemoryExtention.Copy(tempBuffer, moveSpan);
            MemoryExtention.Copy(this.innerBuffer.AsSpan(start, moveLength), tempBuffer);

            this.Length = moveLength;
        }
Пример #2
0
        public bool SetBufferSize(int newSize = 0)
        {
            bool isGrow = false;

            if (this.innerBuffer.Length < newSize)
            {
                var oldBuffer = this.innerBuffer;
                this.innerBuffer = new byte[this.packetSize * ((newSize / this.packetSize) + 1)];
                MemoryExtention.Copy(this.AsSpan(0, oldBuffer.Length), oldBuffer);

                isGrow = true;
            }

            this.Length = newSize;

            return(isGrow);
        }
Пример #3
0
 public void Clear()
 {
     MemoryExtention.Clear(this.innerBuffer);
 }
Пример #4
0
        public void CopyFrom(ReadOnlySpan <byte> fromBuffer, int myOffset = 0)
        {
            var spanBuffer = this.AsSpan(myOffset, Math.Min(fromBuffer.Length, this.Length - myOffset));

            MemoryExtention.Copy(spanBuffer, fromBuffer);
        }
Пример #5
0
        public void Add(ReadOnlySpan <byte> addBuffer)
        {
            this.SetBufferSize(this.Length + addBuffer.Length);

            MemoryExtention.Copy(this.AsSpan(this.Length - addBuffer.Length, addBuffer.Length), addBuffer);
        }