Example #1
0
        public bool TryGet(ref Position position, out Memory <byte> item, bool advance = true)
        {
            if (position == default)
            {
                item = _data;
                if (advance)
                {
                    position = Position.Create(_next);
                }
                return(!_data.IsEmpty || _next != null);
            }
            else if (position.IsEnd)
            {
                item = default;
                return(false);
            }

            var sequence = position.GetItem <MemoryList>();

            item = sequence._data;
            if (advance)
            {
                position = Position.Create(sequence._next);
            }
            return(true);
        }
Example #2
0
        public ReadOnlyBytes Slice(Position start, Position end)
        {
            var kind = Kind;

            switch (kind)
            {
            case Type.Array:
                var startArray = start.GetItem <byte[]>();
                return(new ReadOnlyBytes(startArray, start.Index, end.Index - start.Index));

            case Type.MemoryList:
                var startList = start.GetItem <IMemoryList <byte> >();
                var endList   = end.GetItem <IMemoryList <byte> >();
                return(new ReadOnlyBytes(startList, start.Index, endList, end.Index));

            default:
                throw new NotImplementedException();
            }
        }
Example #3
0
        public ReadOnlyBytes Slice(Position position)
        {
            var kind = Kind;

            switch (kind)
            {
            case Type.Array:
                var array = position.GetItem <byte[]>();
                return(new ReadOnlyBytes(array, position.Index, array.Length - position.Index));

            case Type.MemoryList:
                return(Slice(position, Position.Create((IMemoryList <byte>)_end, _endIndex)));

            default: throw new NotImplementedException();
            }
        }