示例#1
0
        private static NbtDocument Parse(
            ReadOnlyMemory <byte> data,
            NbtOptions options,
            byte[]?extraRentedBytes,
            out int bytesConsumed)
        {
            ReadOnlySpan <byte> dataSpan = data.Span;
            var database = new MetadataDb(data.Length);
            var stack    = new ByteStack <ContainerFrame>(NbtOptions.DefaultMaxDepth, clearOnReturn: false);

            var readerState = new NbtReaderState(options);
            var reader      = new NbtReader(dataSpan, isFinalBlock: true, readerState);

            try
            {
                Parse(ref reader, ref database, ref stack);
                bytesConsumed = (int)reader.BytesConsumed;
            }
            catch
            {
                database.Dispose();
                throw;
            }
            finally
            {
                readerState.Dispose();
                stack.Dispose();
            }

            return(new NbtDocument(data, options, database, extraRentedBytes, isDisposable: true));
        }
示例#2
0
 /// <summary>
 /// Initializes a new instance of the <see cref="NbtReader"/> structure that
 /// processes a read-only span of binary data and indicates whether the input
 /// contains all the data to process.
 /// </summary>
 /// <param name="data">
 /// The binary data to process.
 /// </param>
 /// <param name="isFinalBlock">
 /// true to indicate that the input sequence contains the entire data to process;
 /// false to indicate that the input span contains partial data with more data to follow.
 /// </param>
 /// <param name="state">
 /// An object that contains the reader state. If this is the first call to the constructor,
 /// pass the default state; otherwise, pass the value of the <see cref="CurrentState"/>
 /// property from the previous instance of the <see cref="NbtReader"/>.
 /// </param>
 public NbtReader(ReadOnlySpan <byte> data, bool isFinalBlock, NbtReaderState state) : this()
 {
     _data        = data;
     IsFinalBlock = isFinalBlock;
     _state       = state;
     TagType      = NbtType.Undefined;
 }