// TODO: add debug tree view

        internal NbtElement(NbtDocument parent, int index)
        {
            // parent is usually not null, but the Current property
            // on the enumerators (when initialized as default) can
            // get here with a null.
            Debug.Assert(index >= 0);

            _parent = parent;
            _index  = index;
        }
        public static OperationStatus Read(this NetBinaryReader reader, out NbtDocument?document)
        {
            // TODO:
            // optimize with pooling,
            // read a smarter amount/implement NbtDocument.Parse(Stream)
            // use cached instance for "single End tag" documents

            int toRead = (int)reader.Remaining;

            byte[] nbtData = reader.ReadBytes(toRead);
            document = NbtDocument.Parse(nbtData, out int bytesConsumed);

            int seekBack = bytesConsumed - toRead;

            reader.Seek(seekBack, SeekOrigin.Current);

            return(OperationStatus.Done);
        }