Moved BaseStream field to TagIO
This commit is contained in:
parent
c10deb3900
commit
51efe12e54
|
@ -12,6 +12,10 @@
|
|||
<PackageIcon>icon.png</PackageIcon>
|
||||
<PackageTags>nbt;named binary tag;minecraft;serialization;java;bedrock;pocket edition;varint;varlong</PackageTags>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
|
||||
<DocumentationFile>bin\Release\netstandard2.1\SharpNBT.xml</DocumentationFile>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<None Include="icon.png" Pack="true" Visible="true" PackagePath="" />
|
||||
|
|
|
@ -243,17 +243,7 @@ namespace SharpNBT
|
|||
|
||||
/// <inheritdoc cref="AddIntArray(int[])"/>
|
||||
public TagBuilder AddIntArray([NotNull] IEnumerable<int> values) => AddIntArray(null, values.ToArray());
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Adds a new <see cref="LongArrayTag"/> with the specified <paramref name="values"/> to the tree at the current depth.
|
||||
/// </summary>
|
||||
|
@ -274,14 +264,7 @@ namespace SharpNBT
|
|||
|
||||
/// <inheritdoc cref="AddLongArray(long[])"/>
|
||||
public TagBuilder AddLongArray([NotNull] IEnumerable<long> values) => AddLongArray(null, values.ToArray());
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Adds an existing <see cref="Tag"/> object to the tree at the current depth.
|
||||
/// </summary>
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
using System;
|
||||
using System.IO;
|
||||
using System.Threading.Tasks;
|
||||
using JetBrains.Annotations;
|
||||
|
||||
|
@ -10,6 +11,12 @@ namespace SharpNBT
|
|||
[PublicAPI]
|
||||
public abstract class TagIO : IDisposable
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the underlying stream this instance is operating on.
|
||||
/// </summary>
|
||||
[NotNull]
|
||||
protected Stream BaseStream { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets a flag indicating if byte swapping is required for numeric values, accounting for both the endianness of the host machine and the
|
||||
/// specified <see cref="FormatOptions"/>.
|
||||
|
@ -32,8 +39,10 @@ namespace SharpNBT
|
|||
/// </summary>
|
||||
public FormatOptions FormatOptions { get; }
|
||||
|
||||
protected TagIO(FormatOptions options)
|
||||
protected TagIO([NotNull] Stream stream, FormatOptions options)
|
||||
{
|
||||
BaseStream = stream ?? throw new ArgumentNullException(nameof(stream));
|
||||
|
||||
if (options.HasFlag(FormatOptions.BigEndian))
|
||||
SwapEndian = BitConverter.IsLittleEndian;
|
||||
else if (options.HasFlag(FormatOptions.LittleEndian))
|
||||
|
|
|
@ -18,14 +18,11 @@ namespace SharpNBT
|
|||
/// </summary>
|
||||
public event TagReaderCallback<TagEventArgs> TagRead;
|
||||
|
||||
public event TagReaderCallback<TagHandledEventArgs> TagEncountered;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the underlying stream this <see cref="TagReader"/> is operating on.
|
||||
/// Occurs when a tag has been encountered in the stream, after reading the first byte to determine its <see cref="TagType"/>.
|
||||
/// </summary>
|
||||
[NotNull]
|
||||
protected Stream BaseStream { get; }
|
||||
|
||||
public event TagReaderCallback<TagHandledEventArgs> TagEncountered;
|
||||
|
||||
private readonly bool leaveOpen;
|
||||
|
||||
/// <summary>
|
||||
|
@ -36,9 +33,8 @@ namespace SharpNBT
|
|||
/// <param name="leaveOpen">
|
||||
/// <paramref langword="true"/> to leave the <paramref name="stream"/> object open after disposing the <see cref="TagReader"/>
|
||||
/// object; otherwise, <see langword="false"/>.</param>
|
||||
public TagReader([NotNull] Stream stream, FormatOptions options, bool leaveOpen = false) : base(options)
|
||||
public TagReader([NotNull] Stream stream, FormatOptions options, bool leaveOpen = false) : base(stream, options)
|
||||
{
|
||||
BaseStream = stream ?? throw new ArgumentNullException(nameof(stream));
|
||||
if (!stream.CanRead)
|
||||
throw new IOException("Stream is not opened for reading.");
|
||||
this.leaveOpen = leaveOpen;
|
||||
|
@ -447,11 +443,17 @@ namespace SharpNBT
|
|||
}
|
||||
|
||||
/// <summary>
|
||||
/// Invokes the <see cref="TagRead"/> event when a tag has been fully deserialized from the <see cref="BaseStream"/>.
|
||||
/// Invokes the <see cref="TagRead"/> event when a tag has been fully deserialized from the <see cref="TagIO.BaseStream"/>.
|
||||
/// </summary>
|
||||
/// <param name="tag">The deserialized <see cref="Tag"/> instance.</param>
|
||||
protected virtual void OnTagRead(Tag tag) => TagRead?.Invoke(this, new TagEventArgs(tag.Type, tag));
|
||||
|
||||
/// <summary>
|
||||
/// Invokes the <see cref="TagEncountered"/> event when the stream is positioned at the beginning of a an unread tag.
|
||||
/// </summary>
|
||||
/// <param name="type">The type of tag next to be read from the stream.</param>
|
||||
/// <param name="named">Flag indicating if this tag is named.</param>
|
||||
/// <returns>When handled by an event subscriber, returns a parsed <see cref="Tag"/> instance, otherwise returns <param langword="null">.</param></returns>
|
||||
[CanBeNull]
|
||||
protected virtual Tag OnTagEncountered(TagType type, bool named)
|
||||
{
|
||||
|
|
|
@ -16,12 +16,6 @@ namespace SharpNBT
|
|||
public class TagWriter : TagIO
|
||||
{
|
||||
private readonly bool leaveOpen;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the underlying stream this <see cref="TagReader"/> is operating on.
|
||||
/// </summary>
|
||||
[NotNull]
|
||||
protected Stream BaseStream { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new instance of the <see cref="TagWriter"/> class from the given <paramref name="stream"/>.
|
||||
|
@ -31,9 +25,8 @@ namespace SharpNBT
|
|||
/// <param name="leaveOpen">
|
||||
/// <paramref langword="true"/> to leave the <paramref name="stream"/> object open after disposing the <see cref="TagWriter"/>
|
||||
/// object; otherwise, <see langword="false"/>.</param>
|
||||
public TagWriter([NotNull] Stream stream, FormatOptions options, bool leaveOpen = false) : base(options)
|
||||
public TagWriter([NotNull] Stream stream, FormatOptions options, bool leaveOpen = false) : base(stream, options)
|
||||
{
|
||||
BaseStream = stream ?? throw new ArgumentNullException(nameof(stream));
|
||||
if (!stream.CanWrite)
|
||||
throw new IOException("Stream is not opened for writing.");
|
||||
this.leaveOpen = leaveOpen;
|
||||
|
|
Loading…
Reference in New Issue