Esempio n. 1
0
        public MemoryList Append(Memory <byte> bytes)
        {
            if (_next != null)
            {
                throw new InvalidOperationException("Node cannot be appended");
            }
            var node = new MemoryList(bytes, _virtualIndex + _data.Length);

            _next = node;
            return(node);
        }
Esempio n. 2
0
        public static (MemoryList list, long length) Create(params byte[][] buffers)
        {
            if (buffers.Length == 0 || (buffers.Length == 1 && buffers[0].Length == 0))
            {
                return(new MemoryList(Memory <byte> .Empty), 0);
            }

            MemoryList first = new MemoryList(buffers[0]);
            var        last  = first;

            for (int i = 1; i < buffers.Length; i++)
            {
                last = last.Append(buffers[i]);
            }

            return(first, last.VirtualIndex + last.Memory.Length);
        }
Esempio n. 3
0
        public static (MemoryList first, MemoryList last) Create(params byte[][] buffers)
        {
            if (buffers.Length == 0 || (buffers.Length == 1 && buffers[0].Length == 0))
            {
                var list = new MemoryList(Memory <byte> .Empty);
                return(list, list);
            }

            MemoryList first = new MemoryList(buffers[0]);
            var        last  = first;

            for (int i = 1; i < buffers.Length; i++)
            {
                last = last.Append(buffers[i]);
            }

            return(first, last);
        }
Esempio n. 4
0
        public override string ToString()
        {
            var builder = new StringBuilder();

            builder.Append('[');
            bool first = true;

            for (int i = 0; i < Math.Min(5, _data.Length); i++)
            {
                if (!first)
                {
                    builder.Append(", ");
                }
                first = false;
                builder.Append(_data.Span[i]);
            }
            if (_data.Length > 5 || _next != null)
            {
                builder.Append(", ...");
            }
            builder.Append(']');
            return(builder.ToString());
        }
Esempio n. 5
0
 public MemoryList(Memory <byte> bytes)
 {
     _data         = bytes;
     _next         = null;
     _virtualIndex = 0;
 }