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