Remaining NBT classes refactored and documented.

This commit is contained in:
Justin Aquadro 2011-06-26 06:09:23 +00:00
parent cdee3fb41d
commit 288d3a419a
15 changed files with 1025 additions and 500 deletions

View file

@ -0,0 +1,40 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace Substrate.NBT
{
/// <summary>
/// Defines methods for loading or extracting an NBT tree.
/// </summary>
/// <typeparam name="T">Object type that supports this interface.</typeparam>
public interface INBTObject<T>
{
/// <summary>
/// Attempt to load an NBT tree into the object without validation.
/// </summary>
/// <param name="tree">The root node of an NBT tree.</param>
/// <returns>The object returns itself on success, or null if the tree was unparsable.</returns>
T LoadTree (TagNode tree);
/// <summary>
/// Attempt to load an NBT tree into the object with validation.
/// </summary>
/// <param name="tree">The root node of an NBT tree.</param>
/// <returns>The object returns itself on success, or null if the tree failed validation.</returns>
T LoadTreeSafe (TagNode tree);
/// <summary>
/// Builds an NBT tree from the object's data.
/// </summary>
/// <returns>The root node of an NBT tree representing the object's data.</returns>
TagNode BuildTree ();
/// <summary>
/// Validate an NBT tree, usually against an object-supplied schema.
/// </summary>
/// <param name="tree">The root node of an NBT tree.</param>
/// <returns>Status indicating whether the tree was valid for this object.</returns>
bool ValidateTree (TagNode tree);
}
}

View file

@ -8,40 +8,6 @@ namespace Substrate.NBT
{ {
using Substrate.Utility; using Substrate.Utility;
/// <summary>
/// Defines methods for loading or extracting an NBT tree.
/// </summary>
/// <typeparam name="T">Object type that supports this interface.</typeparam>
public interface INBTObject<T>
{
/// <summary>
/// Attempt to load an NBT tree into the object without validation.
/// </summary>
/// <param name="tree">The root node of an NBT tree.</param>
/// <returns>The object returns itself on success, or null if the tree was unparsable.</returns>
T LoadTree (TagNode tree);
/// <summary>
/// Attempt to load an NBT tree into the object with validation.
/// </summary>
/// <param name="tree">The root node of an NBT tree.</param>
/// <returns>The object returns itself on success, or null if the tree failed validation.</returns>
T LoadTreeSafe (TagNode tree);
/// <summary>
/// Builds an NBT tree from the object's data.
/// </summary>
/// <returns>The root node of an NBT tree representing the object's data.</returns>
TagNode BuildTree ();
/// <summary>
/// Validate an NBT tree, usually against an object-supplied schema.
/// </summary>
/// <param name="tree">The root node of an NBT tree.</param>
/// <returns>Status indicating whether the tree was valid for this object.</returns>
bool ValidateTree (TagNode tree);
}
/// <summary> /// <summary>
/// Contains the root node of an NBT tree and handles IO of tree nodes. /// Contains the root node of an NBT tree and handles IO of tree nodes.
/// </summary> /// </summary>

View file

@ -1,408 +0,0 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace Substrate.NBT
{
[Flags]
public enum SchemaOptions
{
OPTIONAL = 0x1,
CREATE_ON_MISSING = 0x2,
}
public abstract class SchemaNode
{
private string _name;
private SchemaOptions _options;
public string Name
{
get { return _name; }
}
public SchemaOptions Options
{
get { return _options; }
}
public SchemaNode (string name)
{
_name = name;
}
public SchemaNode (string name, SchemaOptions options)
{
_name = name;
_options = options;
}
public virtual TagNode BuildDefaultTree ()
{
return null;
}
}
public sealed class SchemaNodeScaler : SchemaNode
{
private TagType _type;
public TagType Type
{
get { return _type; }
}
public SchemaNodeScaler (string name, TagType type)
: base(name)
{
_type = type;
}
public SchemaNodeScaler (string name, TagType type, SchemaOptions options)
: base(name, options)
{
_type = type;
}
public override TagNode BuildDefaultTree ()
{
switch (_type) {
case TagType.TAG_STRING:
return new TagNodeString();
case TagType.TAG_BYTE:
return new TagNodeByte();
case TagType.TAG_SHORT:
return new TagNodeShort();
case TagType.TAG_INT:
return new TagNodeInt();
case TagType.TAG_LONG:
return new TagNodeLong();
case TagType.TAG_FLOAT:
return new TagNodeFloat();
case TagType.TAG_DOUBLE:
return new TagNodeDouble();
}
return null;
}
}
public sealed class SchemaNodeString : SchemaNode
{
private string _value = "";
private int _length;
public int Length
{
get { return _length; }
}
public string Value
{
get { return _value; }
}
public SchemaNodeString (string name, SchemaOptions options)
: base(name, options)
{
}
public SchemaNodeString (string name, string value)
: base(name)
{
_value = value;
}
public SchemaNodeString (string name, int length)
: base(name)
{
_length = length;
}
public override TagNode BuildDefaultTree ()
{
if (_value.Length > 0) {
return new TagNodeString(_value);
}
return new TagNodeString();
}
}
public sealed class SchemaNodeArray : SchemaNode
{
private int _length;
public int Length
{
get { return _length; }
}
public SchemaNodeArray (string name)
: base(name)
{
_length = 0;
}
public SchemaNodeArray (string name, SchemaOptions options)
: base(name, options)
{
_length = 0;
}
public SchemaNodeArray (string name, int length)
: base(name)
{
_length = length;
}
public SchemaNodeArray (string name, int length, SchemaOptions options)
: base(name, options)
{
_length = length;
}
public override TagNode BuildDefaultTree ()
{
return new TagNodeByteArray(new byte[_length]);
}
}
public sealed class SchemaNodeList : SchemaNode
{
private TagType _type;
private int _length;
private SchemaNode _subschema;
public int Length
{
get { return _length; }
}
public TagType Type
{
get { return _type; }
}
public SchemaNode SubSchema
{
get { return _subschema; }
}
public SchemaNodeList (string name, TagType type)
: base(name)
{
_type = type;
}
public SchemaNodeList (string name, TagType type, SchemaOptions options)
: base(name, options)
{
_type = type;
}
public SchemaNodeList (string name, TagType type, int length)
: base(name)
{
_type = type;
_length = length;
}
public SchemaNodeList (string name, TagType type, int length, SchemaOptions options)
: base(name, options)
{
_type = type;
_length = length;
}
public SchemaNodeList (string name, TagType type, SchemaNode subschema)
: base(name)
{
_type = type;
_subschema = subschema;
}
public SchemaNodeList (string name, TagType type, SchemaNode subschema, SchemaOptions options)
: base(name, options)
{
_type = type;
_subschema = subschema;
}
public SchemaNodeList (string name, TagType type, int length, SchemaNode subschema)
: base(name)
{
_type = type;
_length = length;
_subschema = subschema;
}
public SchemaNodeList (string name, TagType type, int length, SchemaNode subschema, SchemaOptions options)
: base(name, options)
{
_type = type;
_length = length;
_subschema = subschema;
}
public override TagNode BuildDefaultTree ()
{
if (_length == 0) {
return new TagNodeList(_type);
}
TagNodeList list = new TagNodeList(_type);
for (int i = 0; i < _length; i++) {
list.Add(_subschema.BuildDefaultTree());
}
return list;
}
}
public sealed class SchemaNodeCompound : SchemaNode, ICollection<SchemaNode>
{
private List<SchemaNode> _subnodes;
#region ICollection<NBTSchemaNode> Members
public void Add (SchemaNode item)
{
_subnodes.Add(item);
}
public void Clear ()
{
_subnodes.Clear();
}
public bool Contains (SchemaNode item)
{
return _subnodes.Contains(item);
}
public void CopyTo (SchemaNode[] array, int arrayIndex)
{
_subnodes.CopyTo(array, arrayIndex);
}
public int Count
{
get { return _subnodes.Count; }
}
public bool IsReadOnly
{
get { return false; }
}
public bool Remove (SchemaNode item)
{
return _subnodes.Remove(item);
}
#endregion
#region IEnumerable<NBTSchemaNode> Members
public IEnumerator<SchemaNode> GetEnumerator ()
{
return _subnodes.GetEnumerator();
}
#endregion
#region IEnumerable Members
System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator ()
{
return _subnodes.GetEnumerator();
}
#endregion
public SchemaNodeCompound ()
: base("")
{
_subnodes = new List<SchemaNode>();
}
public SchemaNodeCompound (SchemaOptions options)
: base("", options)
{
_subnodes = new List<SchemaNode>();
}
public SchemaNodeCompound (string name)
: base(name)
{
_subnodes = new List<SchemaNode>();
}
public SchemaNodeCompound (string name, SchemaOptions options)
: base(name, options)
{
_subnodes = new List<SchemaNode>();
}
public SchemaNodeCompound (string name, SchemaNode subschema)
: base(name)
{
_subnodes = new List<SchemaNode>();
SchemaNodeCompound schema = subschema as SchemaNodeCompound;
if (schema == null) {
return;
}
foreach (SchemaNode node in schema._subnodes)
{
_subnodes.Add(node);
}
}
public SchemaNodeCompound (string name, SchemaNode subschema, SchemaOptions options)
: base(name, options)
{
_subnodes = new List<SchemaNode>();
SchemaNodeCompound schema = subschema as SchemaNodeCompound;
if (schema == null) {
return;
}
foreach (SchemaNode node in schema._subnodes) {
_subnodes.Add(node);
}
}
public SchemaNodeCompound MergeInto (SchemaNodeCompound tree)
{
foreach (SchemaNode node in _subnodes) {
SchemaNode f = tree._subnodes.Find(n => n.Name == node.Name);
if (f != null) {
continue;
}
tree.Add(node);
}
return tree;
}
public override TagNode BuildDefaultTree ()
{
TagNodeCompound list = new TagNodeCompound();
foreach (SchemaNode node in _subnodes) {
list[node.Name] = node.BuildDefaultTree();
}
return list;
}
}
}

View file

@ -4,36 +4,86 @@ using System.Text;
namespace Substrate.NBT namespace Substrate.NBT
{ {
public delegate void MissingTagHandler (Object o, TagEventArgs e); using Substrate.Utility;
public delegate void InvalidTagTypeHandler (Object o, TagEventArgs e);
public delegate void InvalidTagValueHandler (Object o, TagEventArgs e);
public interface INBTVerifier /// <summary>
/// Indicates how an <see cref="NBTVerifier"/> event processor should respond to returning event handler.
/// </summary>
public enum TagEventCode
{ {
event MissingTagHandler MissingTag; /// <summary>
event InvalidTagTypeHandler InvalidTagType; /// The event processor should process the next event in the chian.
event InvalidTagValueHandler InvalidTagValue; /// </summary>
NEXT,
bool Verify (); /// <summary>
/// The event processor should ignore the verification failure and stop processing any remaining events.
/// </summary>
PASS,
/// <summary>
/// The event processor should fail and stop processing any remaining events.
/// </summary>
FAIL,
} }
/// <summary>
/// Event arguments for <see cref="NBTVerifier"/> failure events.
/// </summary>
public class TagEventArgs : EventArgs public class TagEventArgs : EventArgs
{ {
protected string _tagName; private string _tagName;
protected TagNode _tag; private TagNode _parent;
protected SchemaNode _schema; private TagNode _tag;
private SchemaNode _schema;
/// <summary>
/// Gets the expected name of the <see cref="TagNode"/> referenced by this event.
/// </summary>
public string TagName public string TagName
{ {
get { return _tagName; } get { return _tagName; }
} }
/// <summary>
/// Gets the parent <see cref="TagNode"/> of the <see cref="TagNode"/> referenced by this event, if it exists.
/// </summary>
public TagNode Parent
{
get { return _parent; }
}
/// <summary>
/// Gets the <see cref="TagNode"/> referenced by this event.
/// </summary>
public TagNode Tag
{
get { return _tag; }
}
/// <summary>
/// Gets the <see cref="SchemaNode"/> corresponding to the <see cref="TagNode"/> referenced by this event.
/// </summary>
public SchemaNode Schema
{
get { return _schema; }
}
/// <summary>
/// Constructs a new event argument set.
/// </summary>
/// <param name="tagName">The expected name of a <see cref="TagNode"/>.</param>
public TagEventArgs (string tagName) public TagEventArgs (string tagName)
: base() : base()
{ {
_tagName = tagName; _tagName = tagName;
} }
/// <summary>
/// Constructs a new event argument set.
/// </summary>
/// <param name="tagName">The expected name of a <see cref="TagNode"/>.</param>
/// <param name="tag">The <see cref="TagNode"/> involved in this event.</param>
public TagEventArgs (string tagName, TagNode tag) public TagEventArgs (string tagName, TagNode tag)
: base() : base()
{ {
@ -41,6 +91,11 @@ namespace Substrate.NBT
_tagName = tagName; _tagName = tagName;
} }
/// <summary>
/// Constructs a new event argument set.
/// </summary>
/// <param name="schema">The <see cref="SchemaNode"/> corresponding to the <see cref="TagNode"/> involved in this event.</param>
/// <param name="tag">The <see cref="TagNode"/> involved in this event.</param>
public TagEventArgs (SchemaNode schema, TagNode tag) public TagEventArgs (SchemaNode schema, TagNode tag)
: base() : base()
{ {
@ -49,35 +104,55 @@ namespace Substrate.NBT
} }
} }
public class NBTVerifier : INBTVerifier /// <summary>
/// Verifies the integrity of an NBT tree against a schema definition.
/// </summary>
public class NBTVerifier
{ {
private TagNode _root; private TagNode _root;
private SchemaNode _schema; private SchemaNode _schema;
public event MissingTagHandler MissingTag; /// <summary>
public event InvalidTagTypeHandler InvalidTagType; /// An event that gets fired whenever an expected <see cref="TagNode"/> is not found.
public event InvalidTagValueHandler InvalidTagValue; /// </summary>
public static event Func<TagEventArgs, TagEventCode> MissingTag;
/// <summary>
/// An event that gets fired whenever an expected <see cref="TagNode"/> is of the wrong type and cannot be cast.
/// </summary>
public static event Func<TagEventArgs, TagEventCode> InvalidTagType;
/// <summary>
/// An event that gets fired whenever an expected <see cref="TagNode"/> has a value that violates the schema.
/// </summary>
public static event Func<TagEventArgs, TagEventCode> InvalidTagValue;
private Dictionary<string, TagNode> _scratch = new Dictionary<string,TagNode>(); private Dictionary<string, TagNode> _scratch = new Dictionary<string,TagNode>();
public NBTVerifier () { } /// <summary>
/// Constructs a new <see cref="NBTVerifier"/> object for a given NBT tree and schema.
/// </summary>
/// <param name="root">A <see cref="TagNode"/> representing the root of an NBT tree.</param>
/// <param name="schema">A <see cref="SchemaNode"/> representing the root of a schema definition for the NBT tree.</param>
public NBTVerifier (TagNode root, SchemaNode schema) public NBTVerifier (TagNode root, SchemaNode schema)
{ {
_root = root; _root = root;
_schema = schema; _schema = schema;
} }
public bool Verify () /// <summary>
/// Invokes the verifier.
/// </summary>
/// <returns>Status indicating whether the NBT tree is valid for the given schema.</returns>
public virtual bool Verify ()
{ {
return Verify(_root, _schema); return Verify(null, _root, _schema);
} }
private bool Verify (TagNode tag, SchemaNode schema) private bool Verify (TagNode parent, TagNode tag, SchemaNode schema)
{ {
if (tag == null) { if (tag == null) {
OnMissingTag(new TagEventArgs(schema.Name)); return OnMissingTag(new TagEventArgs(schema.Name));
return false;
} }
SchemaNodeScaler scaler = schema as SchemaNodeScaler; SchemaNodeScaler scaler = schema as SchemaNodeScaler;
@ -105,15 +180,16 @@ namespace Substrate.NBT
return VerifyCompound(tag, compound); return VerifyCompound(tag, compound);
} }
return false; return OnInvalidTagType(new TagEventArgs(schema.Name, tag));
} }
private bool VerifyScaler (TagNode tag, SchemaNodeScaler schema) private bool VerifyScaler (TagNode tag, SchemaNodeScaler schema)
{ {
if (!tag.IsCastableTo(schema.Type)) { if (!tag.IsCastableTo(schema.Type)) {
OnInvalidTagType(new TagEventArgs(schema.Name, tag)); if (!OnInvalidTagType(new TagEventArgs(schema.Name, tag))) {
return false; return false;
} }
}
return true; return true;
} }
@ -122,17 +198,20 @@ namespace Substrate.NBT
{ {
TagNodeString stag = tag as TagNodeString; TagNodeString stag = tag as TagNodeString;
if (stag == null) { if (stag == null) {
OnInvalidTagType(new TagEventArgs(schema, tag)); if (!OnInvalidTagType(new TagEventArgs(schema, tag))) {
return false; return false;
} }
}
if (schema.Length > 0 && stag.Length > schema.Length) { if (schema.Length > 0 && stag.Length > schema.Length) {
OnInvalidTagValue(new TagEventArgs(schema, tag)); if (!OnInvalidTagValue(new TagEventArgs(schema, tag))) {
return false; return false;
} }
}
if (schema.Value != null && stag.Data != schema.Value) { if (schema.Value != null && stag.Data != schema.Value) {
OnInvalidTagValue(new TagEventArgs(schema, tag)); if (!OnInvalidTagValue(new TagEventArgs(schema, tag))) {
return false; return false;
} }
}
return true; return true;
} }
@ -142,13 +221,15 @@ namespace Substrate.NBT
{ {
TagNodeByteArray atag = tag as TagNodeByteArray; TagNodeByteArray atag = tag as TagNodeByteArray;
if (atag == null) { if (atag == null) {
OnInvalidTagType(new TagEventArgs(schema, tag)); if (!OnInvalidTagType(new TagEventArgs(schema, tag))) {
return false; return false;
} }
}
if (schema.Length > 0 && atag.Length != schema.Length) { if (schema.Length > 0 && atag.Length != schema.Length) {
OnInvalidTagValue(new TagEventArgs(schema, tag)); if (!OnInvalidTagValue(new TagEventArgs(schema, tag))) {
return false; return false;
} }
}
return true; return true;
} }
@ -157,17 +238,20 @@ namespace Substrate.NBT
{ {
TagNodeList ltag = tag as TagNodeList; TagNodeList ltag = tag as TagNodeList;
if (ltag == null) { if (ltag == null) {
OnInvalidTagType(new TagEventArgs(schema, tag)); if (!OnInvalidTagType(new TagEventArgs(schema, tag))) {
return false; return false;
} }
}
if (ltag.Count > 0 && ltag.ValueType != schema.Type) { if (ltag.Count > 0 && ltag.ValueType != schema.Type) {
OnInvalidTagValue(new TagEventArgs(schema, tag)); if (!OnInvalidTagValue(new TagEventArgs(schema, tag))) {
return false; return false;
} }
}
if (schema.Length > 0 && ltag.Count != schema.Length) { if (schema.Length > 0 && ltag.Count != schema.Length) {
OnInvalidTagValue(new TagEventArgs(schema, tag)); if (!OnInvalidTagValue(new TagEventArgs(schema, tag))) {
return false; return false;
} }
}
// Patch up empty lists // Patch up empty lists
//if (schema.Length == 0) { //if (schema.Length == 0) {
@ -180,7 +264,7 @@ namespace Substrate.NBT
if (schema.SubSchema != null) { if (schema.SubSchema != null) {
foreach (TagNode v in ltag) { foreach (TagNode v in ltag) {
pass = Verify(v, schema.SubSchema) && pass; pass = Verify(tag, v, schema.SubSchema) && pass;
} }
} }
@ -191,9 +275,10 @@ namespace Substrate.NBT
{ {
TagNodeCompound ctag = tag as TagNodeCompound; TagNodeCompound ctag = tag as TagNodeCompound;
if (ctag == null) { if (ctag == null) {
OnInvalidTagType(new TagEventArgs(schema, tag)); if (!OnInvalidTagType(new TagEventArgs(schema, tag))) {
return false; return false;
} }
}
bool pass = true; bool pass = true;
@ -211,7 +296,7 @@ namespace Substrate.NBT
} }
} }
pass = Verify(value, node) && pass; pass = Verify(tag, value, node) && pass;
} }
foreach (KeyValuePair<string, TagNode> item in _scratch) { foreach (KeyValuePair<string, TagNode> item in _scratch) {
@ -225,26 +310,71 @@ namespace Substrate.NBT
#region Event Handlers #region Event Handlers
protected void OnMissingTag (TagEventArgs e) /// <summary>
/// Processes registered events for <see cref="MissingTag"/> whenever an expected <see cref="TagNode"/> is not found.
/// </summary>
/// <param name="e">Arguments for this event.</param>
/// <returns>Status indicating whether this event can be ignored.</returns>
protected virtual bool OnMissingTag (TagEventArgs e)
{ {
if (MissingTag != null) { if (MissingTag != null) {
MissingTag(this, e); foreach (Func<TagEventArgs, TagEventCode> func in MissingTag.GetInvocationList()) {
TagEventCode code = func(e);
switch (code) {
case TagEventCode.FAIL:
return false;
case TagEventCode.PASS:
return true;
}
} }
} }
protected void OnInvalidTagType (TagEventArgs e) return false;
}
/// <summary>
/// Processes registered events for <see cref="InvalidTagType"/> whenever an expected <see cref="TagNode"/> is of the wrong type and cannot be cast.
/// </summary>
/// <param name="e">Arguments for this event.</param>
/// <returns>Status indicating whether this event can be ignored.</returns>
protected virtual bool OnInvalidTagType (TagEventArgs e)
{ {
if (InvalidTagType != null) { if (InvalidTagType != null) {
InvalidTagType(this, e); foreach (Func<TagEventArgs, TagEventCode> func in InvalidTagType.GetInvocationList()) {
TagEventCode code = func(e);
switch (code) {
case TagEventCode.FAIL:
return false;
case TagEventCode.PASS:
return true;
}
} }
} }
protected void OnInvalidTagValue (TagEventArgs e) return false;
}
/// <summary>
/// Processes registered events for <see cref="InvalidTagValue"/> whenever an expected <see cref="TagNode"/> has a value that violates the schema.
/// </summary>
/// <param name="e">Arguments for this event.</param>
/// <returns>Status indicating whether this event can be ignored.</returns>
protected virtual bool OnInvalidTagValue (TagEventArgs e)
{ {
if (InvalidTagValue != null) { if (InvalidTagValue != null) {
InvalidTagValue(this, e); foreach (Func<TagEventArgs, TagEventCode> func in InvalidTagValue.GetInvocationList()) {
TagEventCode code = func(e);
switch (code) {
case TagEventCode.FAIL:
return false;
case TagEventCode.PASS:
return true;
} }
} }
}
return false;
}
#endregion #endregion
} }

View file

@ -0,0 +1,60 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace Substrate.NBT
{
/// <summary>
/// A node in an NBT schema definition, used to define what values are considered valid for a given NBT node.
/// </summary>
public abstract class SchemaNode
{
private string _name;
private SchemaOptions _options;
/// <summary>
/// Gets the name of an expected NBT node.
/// </summary>
public string Name
{
get { return _name; }
}
/// <summary>
/// Gets additional schema options defined for this node.
/// </summary>
public SchemaOptions Options
{
get { return _options; }
}
/// <summary>
/// Constructs a new <see cref="SchemaNode"/> representing a <see cref="TagNode"/> named <paramref name="name"/>.
/// </summary>
/// <param name="name">The name of the corresponding <see cref="TagNode"/>.</param>
protected SchemaNode (string name)
{
_name = name;
}
/// <summary>
/// Constructs a new <see cref="SchemaNode"/> with additional options.
/// </summary>
/// <param name="name">The name of the corresponding <see cref="TagNode"/>.</param>
/// <param name="options">One or more option flags modifying the processing of this node.</param>
protected SchemaNode (string name, SchemaOptions options)
{
_name = name;
_options = options;
}
/// <summary>
/// Construct a sensible default NBT tree representative of this schema node.
/// </summary>
/// <returns>A <see cref="TagNode"/> that is valid for this schema node.</returns>
public virtual TagNode BuildDefaultTree ()
{
return null;
}
}
}

View file

@ -0,0 +1,81 @@
using System;
namespace Substrate.NBT
{
/// <summary>
/// A concrete <see cref="SchemaNode"/> representing a <see cref="TagNodeByteArray"/>.
/// </summary>
public sealed class SchemaNodeArray : SchemaNode
{
private int _length;
/// <summary>
/// Gets the expected length of the corresponding byte array.
/// </summary>
public int Length
{
get { return _length; }
}
/// <summary>
/// Indicates whether there is an expected length of the corresponding byte array.
/// </summary>
public bool HasExpectedLength
{
get { return _length > 0; }
}
/// <summary>
/// Constructs a new <see cref="SchemaNodeArray"/> representing a <see cref="TagNodeByteArray"/> named <paramref name="name"/>.
/// </summary>
/// <param name="name">The name of the corresponding <see cref="TagNodeByteArray"/>.</param>
public SchemaNodeArray (string name)
: base(name)
{
_length = 0;
}
/// <summary>
/// Constructs a new <see cref="SchemaNodeArray"/> with additional options.
/// </summary>
/// <param name="name">The name of the corresponding <see cref="TagNodeByteArray"/>.</param>
/// <param name="options">One or more option flags modifying the processing of this node.</param>
public SchemaNodeArray (string name, SchemaOptions options)
: base(name, options)
{
_length = 0;
}
/// <summary>
/// Constructs a new <see cref="SchemaNodeArray"/> representing a <see cref="TagNodeByteArray"/> named <paramref name="name"/> with expected length <paramref name="length"/>.
/// </summary>
/// <param name="name">The name of the corresponding <see cref="TagNodeByteArray"/>.</param>
/// <param name="length">The expected length of corresponding byte array.</param>
public SchemaNodeArray (string name, int length)
: base(name)
{
_length = length;
}
/// <summary>
/// Constructs a new <see cref="SchemaNodeArray"/> with additional options.
/// </summary>
/// <param name="name">The name of the corresponding <see cref="TagNodeByteArray"/>.</param>
/// <param name="length">The expected length of corresponding byte array.</param>
/// <param name="options">One or more option flags modifying the processing of this node.</param>
public SchemaNodeArray (string name, int length, SchemaOptions options)
: base(name, options)
{
_length = length;
}
/// <summary>
/// Constructs a default <see cref="TagNodeByteArray"/> satisfying the constraints of this node.
/// </summary>
/// <returns>A <see cref="TagNodeString"/> with a sensible default value.</returns>
public override TagNode BuildDefaultTree ()
{
return new TagNodeByteArray(new byte[_length]);
}
}
}

View file

@ -0,0 +1,219 @@
using System;
using System.Collections.Generic;
namespace Substrate.NBT
{
/// <summary>
/// A concrete <see cref="SchemaNode"/> representing a <see cref="TagNodeCompound"/>.
/// </summary>
public sealed class SchemaNodeCompound : SchemaNode, ICollection<SchemaNode>
{
private List<SchemaNode> _subnodes;
#region ICollection<NBTSchemaNode> Members
/// <summary>
/// Adds a <see cref="SchemaNode"/> as a child of this node.
/// </summary>
/// <param name="item">The <see cref="SchemaNode"/> to add.</param>
public void Add (SchemaNode item)
{
_subnodes.Add(item);
}
/// <summary>
/// Removes all <see cref="SchemaNode"/> objects from the node.
/// </summary>
public void Clear ()
{
_subnodes.Clear();
}
/// <summary>
/// Checks if a <see cref="SchemaNode"/> is a child of this node.
/// </summary>
/// <param name="item">The <see cref="SchemaNode"/> to check for existance.</param>
/// <returns>Status indicating if the <see cref="SchemaNode"/> exists as a child of this node.</returns>
public bool Contains (SchemaNode item)
{
return _subnodes.Contains(item);
}
/// <summary>
/// Copies all child <see cref="SchemaNode"/> objects of this node to a compatible one-dimensional array, starting at the specified index of the target array.
/// </summary>
/// <param name="array">The one-dimensional <see cref="Array"/> that is the destination of the subnodes copied. The Array must have zero-based indexing.</param>
/// <param name="arrayIndex">The zero-based index in <paramref name="array"/> at which copying begins.</param>
public void CopyTo (SchemaNode[] array, int arrayIndex)
{
_subnodes.CopyTo(array, arrayIndex);
}
/// <summary>
/// Gets the number of child <see cref="SchemaNode"/> objects in this node.
/// </summary>
public int Count
{
get { return _subnodes.Count; }
}
/// <summary>
/// Gets a value indicating whether the node is readonly.
/// </summary>
public bool IsReadOnly
{
get { return false; }
}
/// <summary>
/// Removes the first occurance of a <see cref="SchemaNode"/> from this node.
/// </summary>
/// <param name="item">The <see cref="SchemaNode"/> to remove.</param>
/// <returns>Status indicating whether a <see cref="SchemaNode"/> was removed.</returns>
public bool Remove (SchemaNode item)
{
return _subnodes.Remove(item);
}
#endregion
#region IEnumerable<SchemaNode> Members
/// <summary>
/// Iterates through all of the <see cref="SchemaNode"/> objects in this <see cref="SchemaNodeCompound"/>.
/// </summary>
/// <returns>An enumerator for this node.</returns>
public IEnumerator<SchemaNode> GetEnumerator ()
{
return _subnodes.GetEnumerator();
}
#endregion
#region IEnumerable Members
/// <summary>
/// Iterates through all of the <see cref="SchemaNode"/> objects in this <see cref="SchemaNodeCompound"/>.
/// </summary>
/// <returns>An enumerator for this node.</returns>
System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator ()
{
return _subnodes.GetEnumerator();
}
#endregion
/// <summary>
/// Constructs a new <see cref="SchemaNodeCompound"/> representing a root <see cref="TagNodeCompound"/>.
/// </summary>
public SchemaNodeCompound ()
: base("")
{
_subnodes = new List<SchemaNode>();
}
/// <summary>
/// Constructs a new <see cref="SchemaNodeCompound"/> with additional options.
/// </summary>
/// <param name="options">One or more option flags modifying the processing of this node.</param>
public SchemaNodeCompound (SchemaOptions options)
: base("", options)
{
_subnodes = new List<SchemaNode>();
}
/// <summary>
/// Constructs a new <see cref="SchemaNodeCompound"/> representing a <see cref="TagNodeCompound"/> named <paramref name="name"/>.
/// </summary>
/// <param name="name">The name of the corresponding <see cref="TagNodeCompound"/>.</param>
public SchemaNodeCompound (string name)
: base(name)
{
_subnodes = new List<SchemaNode>();
}
/// <summary>
/// Constructs a new <see cref="SchemaNodeCompound"/> with additional options.
/// </summary>
/// <param name="name">The name of the corresponding <see cref="TagNodeCompound"/>.</param>
/// <param name="options">One or more option flags modifying the processing of this node.</param>
public SchemaNodeCompound (string name, SchemaOptions options)
: base(name, options)
{
_subnodes = new List<SchemaNode>();
}
/// <summary>
/// Constructs a new <see cref="SchemaNodeCompound"/> representing a <see cref="TagNodeCompound"/> named <paramref name="name"/> matching the given schema.
/// </summary>
/// <param name="name">The name of the corresponding <see cref="TagNodeCompound"/>.</param>
/// <param name="subschema">A <see cref="SchemaNodeCompound"/> representing a schema to verify against the corresponding <see cref="TagNodeCompound"/>.</param>
public SchemaNodeCompound (string name, SchemaNode subschema)
: base(name)
{
_subnodes = new List<SchemaNode>();
SchemaNodeCompound schema = subschema as SchemaNodeCompound;
if (schema == null) {
return;
}
foreach (SchemaNode node in schema._subnodes) {
_subnodes.Add(node);
}
}
/// <summary>
/// Constructs a new <see cref="SchemaNodeCompound"/> with additional options.
/// </summary>
/// <param name="name">The name of the corresponding <see cref="TagNodeCompound"/>.</param>
/// <param name="subschema">A <see cref="SchemaNodeCompound"/> representing a schema to verify against the corresponding <see cref="TagNodeCompound"/>.</param>
/// <param name="options">One or more option flags modifying the processing of this node.</param>
public SchemaNodeCompound (string name, SchemaNode subschema, SchemaOptions options)
: base(name, options)
{
_subnodes = new List<SchemaNode>();
SchemaNodeCompound schema = subschema as SchemaNodeCompound;
if (schema == null) {
return;
}
foreach (SchemaNode node in schema._subnodes) {
_subnodes.Add(node);
}
}
/// <summary>
/// Copies all the elements of this <see cref="SchemaNodeCompound"/> into <paramref name="tree"/>.
/// </summary>
/// <param name="tree">The destination <see cref="SchemaNodeCompound"/> to copy <see cref="SchemaNode"/> elements into.</param>
/// <returns>A reference to <paramref name="tree"/>.</returns>
public SchemaNodeCompound MergeInto (SchemaNodeCompound tree)
{
foreach (SchemaNode node in _subnodes) {
SchemaNode f = tree._subnodes.Find(n => n.Name == node.Name);
if (f != null) {
continue;
}
tree.Add(node);
}
return tree;
}
/// <summary>
/// Constructs a default <see cref="TagNodeCompound"/> satisfying the constraints of this node.
/// </summary>
/// <returns>A <see cref="TagNodeCompound"/> with a sensible default value. A default child <see cref="TagNode"/> is created for every <see cref="SchemaNode"/> contained in this <see cref="SchemaNodeCompound"/>.</returns>
public override TagNode BuildDefaultTree ()
{
TagNodeCompound list = new TagNodeCompound();
foreach (SchemaNode node in _subnodes) {
list[node.Name] = node.BuildDefaultTree();
}
return list;
}
}
}

View file

@ -0,0 +1,172 @@
using System;
namespace Substrate.NBT
{
/// <summary>
/// A concrete <see cref="SchemaNode"/> representing a <see cref="TagNodeList"/>.
/// </summary>
public sealed class SchemaNodeList : SchemaNode
{
private TagType _type;
private int _length;
private SchemaNode _subschema;
/// <summary>
/// Gets the expected number of items contained in the corresponding <see cref="TagNodeList"/>.
/// </summary>
public int Length
{
get { return _length; }
}
/// <summary>
/// Gets the expected <see cref="TagType"/> of the items contained in the corresponding <see cref="TagNodeList"/>.
/// </summary>
public TagType Type
{
get { return _type; }
}
/// <summary>
/// Gets a <see cref="SchemaNode"/> representing a schema that items contained in the corresponding <see cref="TagNodeList"/> should be verified against.
/// </summary>
public SchemaNode SubSchema
{
get { return _subschema; }
}
/// <summary>
/// Indicates whether there is an expected number of items of the corresponding <see cref="TagNodeList"/>.
/// </summary>
public bool HasExpectedLength
{
get { return _length > 0; }
}
/// <summary>
/// Constructs a new <see cref="SchemaNodeList"/> representing a <see cref="TagNodeList"/> named <paramref name="name"/> containing items of type <paramref name="type"/>.
/// </summary>
/// <param name="name">The name of the corresponding <see cref="TagNodeList"/>.</param>
/// <param name="type">The type of items contained in the corresponding <see cref="TagNodeList"/>.</param>
public SchemaNodeList (string name, TagType type)
: base(name)
{
_type = type;
}
/// <summary>
/// Constructs a new <see cref="SchemaNodeList"/> with additional options.
/// </summary>
/// <param name="name">The name of the corresponding <see cref="TagNodeList"/>.</param>
/// <param name="type">The type of items contained in the corresponding <see cref="TagNodeList"/>.</param>
/// <param name="options">One or more option flags modifying the processing of this node.</param>
public SchemaNodeList (string name, TagType type, SchemaOptions options)
: base(name, options)
{
_type = type;
}
/// <summary>
/// Constructs a new <see cref="SchemaNodeList"/> representing a <see cref="TagNodeList"/> named <paramref name="name"/> containing <paramref name="length"/> items of type <paramref name="type"/>.
/// </summary>
/// <param name="name">The name of the corresponding <see cref="TagNodeList"/>.</param>
/// <param name="type">The type of items contained in the corresponding <see cref="TagNodeList"/>.</param>
/// <param name="length">The number of items contained in the corresponding <see cref="TagNodeList"/>.</param>
public SchemaNodeList (string name, TagType type, int length)
: base(name)
{
_type = type;
_length = length;
}
/// <summary>
/// Constructs a new <see cref="SchemaNodeList"/> with additional options.
/// </summary>
/// <param name="name">The name of the corresponding <see cref="TagNodeList"/>.</param>
/// <param name="type">The type of items contained in the corresponding <see cref="TagNodeList"/>.</param>
/// <param name="length">The number of items contained in the corresponding <see cref="TagNodeList"/>.</param>
/// <param name="options">One or more option flags modifying the processing of this node.</param>
public SchemaNodeList (string name, TagType type, int length, SchemaOptions options)
: base(name, options)
{
_type = type;
_length = length;
}
/// <summary>
/// Constructs a new <see cref="SchemaNodeList"/> representing a <see cref="TagNodeList"/> named <paramref name="name"/> containing items of type <paramref name="type"/> matching the given schema.
/// </summary>
/// <param name="name">The name of the corresponding <see cref="TagNodeList"/>.</param>
/// <param name="type">The type of items contained in the corresponding <see cref="TagNodeList"/>.</param>
/// <param name="subschema">A <see cref="SchemaNode"/> representing a schema to verify against items contained in the corresponding <see cref="TagNodeList"/>.</param>
public SchemaNodeList (string name, TagType type, SchemaNode subschema)
: base(name)
{
_type = type;
_subschema = subschema;
}
/// <summary>
/// Constructs a new <see cref="SchemaNodeList"/> with additional options.
/// </summary>
/// <param name="name">The name of the corresponding <see cref="TagNodeList"/>.</param>
/// <param name="type">The type of items contained in the corresponding <see cref="TagNodeList"/>.</param>
/// <param name="subschema">A <see cref="SchemaNode"/> representing a schema to verify against items contained in the corresponding <see cref="TagNodeList"/>.</param>
/// <param name="options">One or more option flags modifying the processing of this node.</param>
public SchemaNodeList (string name, TagType type, SchemaNode subschema, SchemaOptions options)
: base(name, options)
{
_type = type;
_subschema = subschema;
}
/// <summary>
/// Constructs a new <see cref="SchemaNodeList"/> representing a <see cref="TagNodeList"/> named <paramref name="name"/> containing <paramref name="length"/> items of type <paramref name="type"/> matching the given schema.
/// </summary>
/// <param name="name">The name of the corresponding <see cref="TagNodeList"/>.</param>
/// <param name="type">The type of items contained in the corresponding <see cref="TagNodeList"/>.</param>
/// <param name="length">The number of items contained in the corresponding <see cref="TagNodeList"/>.</param>
/// <param name="subschema">A <see cref="SchemaNode"/> representing a schema to verify against items contained in the corresponding <see cref="TagNodeList"/>.</param>
public SchemaNodeList (string name, TagType type, int length, SchemaNode subschema)
: base(name)
{
_type = type;
_length = length;
_subschema = subschema;
}
/// <summary>
/// Constructs a new <see cref="SchemaNodeList"/> with additional options.
/// </summary>
/// <param name="name">The name of the corresponding <see cref="TagNodeList"/>.</param>
/// <param name="type">The type of items contained in the corresponding <see cref="TagNodeList"/>.</param>
/// <param name="length">The number of items contained in the corresponding <see cref="TagNodeList"/>.</param>
/// <param name="subschema">A <see cref="SchemaNode"/> representing a schema to verify against items contained in the corresponding <see cref="TagNodeList"/>.</param>
/// <param name="options">One or more option flags modifying the processing of this node.</param>
public SchemaNodeList (string name, TagType type, int length, SchemaNode subschema, SchemaOptions options)
: base(name, options)
{
_type = type;
_length = length;
_subschema = subschema;
}
/// <summary>
/// Constructs a default <see cref="TagNodeList"/> satisfying the constraints of this node.
/// </summary>
/// <returns>A <see cref="TagNodeList"/> with a sensible default value. If a length is specified, default child <see cref="TagNode"/> objects of the necessary type will be created and added to the <see cref="TagNodeList"/>.</returns>
public override TagNode BuildDefaultTree ()
{
if (_length == 0) {
return new TagNodeList(_type);
}
TagNodeList list = new TagNodeList(_type);
for (int i = 0; i < _length; i++) {
list.Add(_subschema.BuildDefaultTree());
}
return list;
}
}
}

View file

@ -0,0 +1,75 @@
using System;
namespace Substrate.NBT
{
/// <summary>
/// A concrete <see cref="SchemaNode"/> representing a scaler-type <see cref="TagNode"/>.
/// </summary>
public sealed class SchemaNodeScaler : SchemaNode
{
private TagType _type;
/// <summary>
/// Gets the scaler <see cref="TagType"/> that this node represents.
/// </summary>
public TagType Type
{
get { return _type; }
}
/// <summary>
/// Constructs a new <see cref="SchemaNodeScaler"/> representing a <see cref="TagNode"/> named <paramref name="name"/> and of type <paramref name="type"/>.
/// </summary>
/// <param name="name">The name of the corresponding <see cref="TagNode"/>.</param>
/// <param name="type">The type of the corresponding <see cref="TagNode"/>, restricted to scaler types.</param>
public SchemaNodeScaler (string name, TagType type)
: base(name)
{
_type = type;
}
/// <summary>
/// Constructs a new <see cref="SchemaNodeScaler"/> with additional options.
/// </summary>
/// <param name="name">The name of the corresponding <see cref="TagNode"/>.</param>
/// <param name="type">The type of the corresponding <see cref="TagNode"/>, restricted to scaler types.</param>
/// <param name="options">One or more option flags modifying the processing of this node.</param>
public SchemaNodeScaler (string name, TagType type, SchemaOptions options)
: base(name, options)
{
_type = type;
}
/// <summary>
/// Constructs a default <see cref="TagNode"/> according to the <see cref="TagType"/> this node represents.
/// </summary>
/// <returns>A <see cref="TagNode"/> with a sensible default value.</returns>
public override TagNode BuildDefaultTree ()
{
switch (_type) {
case TagType.TAG_STRING:
return new TagNodeString();
case TagType.TAG_BYTE:
return new TagNodeByte();
case TagType.TAG_SHORT:
return new TagNodeShort();
case TagType.TAG_INT:
return new TagNodeInt();
case TagType.TAG_LONG:
return new TagNodeLong();
case TagType.TAG_FLOAT:
return new TagNodeFloat();
case TagType.TAG_DOUBLE:
return new TagNodeDouble();
}
return null;
}
}
}

View file

@ -0,0 +1,116 @@
using System;
namespace Substrate.NBT
{
/// <summary>
/// A concrete <see cref="SchemaNode"/> representing a <see cref="TagNodeString"/>.
/// </summary>
public sealed class SchemaNodeString : SchemaNode
{
private string _value = "";
private int _length;
/// <summary>
/// Gets the maximum length of a valid string.
/// </summary>
public int Length
{
get { return _length; }
}
/// <summary>
/// Gets the expected value of a valid string.
/// </summary>
/// <remarks>A <see cref="TagNodeString"/> must be set to this value to be considered valid.</remarks>
public string Value
{
get { return _value; }
}
/// <summary>
/// Indicates whether there is a maximum-length constraint on strings in this node.
/// </summary>
public bool HasMaxLength
{
get { return _length > 0; }
}
/// <summary>
/// Constructs a new <see cref="SchemaNodeString"/> representing a <see cref="TagNodeString"/> named <paramref name="name"/>.
/// </summary>
/// <param name="name">The name of the corresponding <see cref="TagNodeString"/>.</param>
public SchemaNodeString (string name)
: base(name)
{
}
/// <summary>
/// Constructs a new <see cref="SchemaNodeString"/> with additional options.
/// </summary>
/// <param name="name">The name of the corresponding <see cref="TagNodeString"/>.</param>
/// <param name="options">One or more option flags modifying the processing of this node.</param>
public SchemaNodeString (string name, SchemaOptions options)
: base(name, options)
{
}
/// <summary>
/// Constructs a new <see cref="SchemaNodeString"/> representing a <see cref="TagNodeString"/> named <paramref name="name"/> set to <paramref name="value"/>.
/// </summary>
/// <param name="name">The name of the corresponding <see cref="TagNodeString"/>.</param>
/// <param name="value">The value that the corresponding <see cref="TagNodeString"/> must be set to.</param>
public SchemaNodeString (string name, string value)
: base(name)
{
_value = value;
}
/// <summary>
/// Constructs a new <see cref="SchemaNodeString"/> with additional options.
/// </summary>
/// <param name="name">The name of the corresponding <see cref="TagNodeString"/>.</param>
/// <param name="value">The value that the corresponding <see cref="TagNodeString"/> must be set to.</param>
/// <param name="options">One or more option flags modifying the processing of this node.</param>
public SchemaNodeString (string name, string value, SchemaOptions options)
: base(name, options)
{
_value = value;
}
/// <summary>
/// Constructs a new <see cref="SchemaNodeString"/> representing a <see cref="TagNodeString"/> named <paramref name="name"/> with maximum length <paramref name="length"/>.
/// </summary>
/// <param name="name">The name of the corresponding <see cref="TagNodeString"/>.</param>
/// <param name="length">The maximum length of strings in the corresponding <see cref="TagNodeString"/>.</param>
public SchemaNodeString (string name, int length)
: base(name)
{
_length = length;
}
/// <summary>
/// Constructs a new <see cref="SchemaNodeString"/> with additional options.
/// </summary>
/// <param name="name">The name of the corresponding <see cref="TagNodeString"/>.</param>
/// <param name="length">The maximum length of strings in the corresponding <see cref="TagNodeString"/>.</param>
/// <param name="options">One or more option flags modifying the processing of this node.</param>
public SchemaNodeString (string name, int length, SchemaOptions options)
: base(name, options)
{
_length = length;
}
/// <summary>
/// Constructs a default <see cref="TagNodeString"/> satisfying the constraints of this node.
/// </summary>
/// <returns>A <see cref="TagNodeString"/> with a sensible default value. If this node represents a particular string, the <see cref="TagNodeString"/> constructed will be set to that string.</returns>
public override TagNode BuildDefaultTree ()
{
if (_value.Length > 0) {
return new TagNodeString(_value);
}
return new TagNodeString();
}
}
}

View file

@ -0,0 +1,21 @@
using System;
namespace Substrate.NBT
{
/// <summary>
/// Additional options that modify the processing of a <see cref="SchemaNode"/>.
/// </summary>
[Flags]
public enum SchemaOptions
{
/// <summary>
/// Any <see cref="SchemaNode"/> with this option will not throw an error if the corresponding <see cref="TagNode"/> is missing.
/// </summary>
OPTIONAL = 0x1,
/// <summary>
/// If a <see cref="TagNode"/> cannot be found for a <see cref="SchemaNode"/> marked with this option, a sensible default <see cref="TagNode"/> will be created and inserted into the tree.
/// </summary>
CREATE_ON_MISSING = 0x2,
}
}

View file

@ -81,7 +81,7 @@ namespace Substrate.NBT
/// <summary> /// <summary>
/// Converts a system double to a double node representing the same value. /// Converts a system double to a double node representing the same value.
/// </summary> /// </summary>
/// <param name="f">A double value.</param> /// <param name="d">A double value.</param>
/// <returns>A new double node containing the given value.</returns> /// <returns>A new double node containing the given value.</returns>
public static implicit operator TagNodeDouble (double d) public static implicit operator TagNodeDouble (double d)
{ {

View file

@ -89,7 +89,7 @@ namespace Substrate.NBT
/// <summary> /// <summary>
/// Converts a string node to a system string representing the same data. /// Converts a string node to a system string representing the same data.
/// </summary> /// </summary>
/// <param name="b">A string node.</param> /// <param name="s">A string node.</param>
/// <returns>A system string set to the node's data.</returns> /// <returns>A system string set to the node's data.</returns>
public static implicit operator string (TagNodeString s) public static implicit operator string (TagNodeString s)
{ {

View file

@ -0,0 +1,48 @@
using System;
namespace Substrate.NBT
{
using Substrate.Utility;
/// <summary>
/// A collection of static methods that can be hooked into <see cref="NBTVerifier"/> events for logging NBT errors to the console.
/// </summary>
public static class VerifierLogger
{
/// <summary>
/// Logs an occurance of a missing tag error, and advances to the next event in the event chain.
/// </summary>
/// <param name="e">Data about the NBT node being verified.</param>
/// <returns>A <see cref="TagEventCode"/> indicating whether event processing should pass, fail, or advance.</returns>
public static TagEventCode MissingTagHandler (TagEventArgs e)
{
Console.WriteLine("Missing Tag Error: '{0}'", e.TagName);
return TagEventCode.NEXT;
}
/// <summary>
/// Logs an occurance of an invalid tag type error, and advances to the next event in the event chain.
/// </summary>
/// <param name="e">Data about the NBT node being verified.</param>
/// <returns>A <see cref="TagEventCode"/> indicating whether event processing should pass, fail, or advance.</returns>
public static TagEventCode InvalidTagTypeHandler (TagEventArgs e)
{
Console.WriteLine("Invalid Tag Type Error: '{0}' has type '{1}', expected '{2}'", e.TagName, e.Tag.GetTagType(), e.Schema.ToString());
return TagEventCode.NEXT;
}
/// <summary>
/// Logs an occurance of an invalid tag value error, and advances to the next event in the event chain.
/// </summary>
/// <param name="e">Data about the NBT node being verified.</param>
/// <returns>A <see cref="TagEventCode"/> indicating whether event processing should pass, fail, or advance.</returns>
public static TagEventCode InvalidTagValueHandler (TagEventArgs e)
{
Console.WriteLine("Invalid Tag Value Error: '{0}' of type '{1}' is set to invalid value '{2}'", e.TagName, e.Tag.GetTagType(), e.Tag.ToString());
return TagEventCode.NEXT;
}
}
}

View file

@ -60,10 +60,6 @@
<HintPath>Assemblies\Ionic.Zlib.dll</HintPath> <HintPath>Assemblies\Ionic.Zlib.dll</HintPath>
</Reference> </Reference>
<Reference Include="System" /> <Reference Include="System" />
<Reference Include="System.Data" />
<Reference Include="System.Drawing" />
<Reference Include="System.Windows.Forms" />
<Reference Include="System.Xml" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Compile Include="Source\BlockFluid.cs" /> <Compile Include="Source\BlockFluid.cs" />
@ -76,6 +72,14 @@
<Compile Include="Source\BlockLight.cs" /> <Compile Include="Source\BlockLight.cs" />
<Compile Include="Source\BlockTileEntities.cs" /> <Compile Include="Source\BlockTileEntities.cs" />
<Compile Include="Source\Level.cs" /> <Compile Include="Source\Level.cs" />
<Compile Include="Source\NBT\INBTObject.cs" />
<Compile Include="Source\NBT\SchemaNode.cs" />
<Compile Include="Source\NBT\SchemaNodeArray.cs" />
<Compile Include="Source\NBT\SchemaNodeCompound.cs" />
<Compile Include="Source\NBT\SchemaNodeList.cs" />
<Compile Include="Source\NBT\SchemaNodeScaler.cs" />
<Compile Include="Source\NBT\SchemaNodeString.cs" />
<Compile Include="Source\NBT\SchemaOptions.cs" />
<Compile Include="Source\NBT\TagNode.cs" /> <Compile Include="Source\NBT\TagNode.cs" />
<Compile Include="Source\NBT\TagNodeByteArray.cs" /> <Compile Include="Source\NBT\TagNodeByteArray.cs" />
<Compile Include="Source\NBT\TagNodeCompound.cs" /> <Compile Include="Source\NBT\TagNodeCompound.cs" />
@ -89,6 +93,7 @@
<Compile Include="Source\NBT\TagType.cs" /> <Compile Include="Source\NBT\TagType.cs" />
<Compile Include="Source\NBT\TagNodeByte.cs" /> <Compile Include="Source\NBT\TagNodeByte.cs" />
<Compile Include="Source\NBT\TagNodeNull.cs" /> <Compile Include="Source\NBT\TagNodeNull.cs" />
<Compile Include="Source\NBT\VerifierLogger.cs" />
<Compile Include="Source\PlayerManager.cs" /> <Compile Include="Source\PlayerManager.cs" />
<Compile Include="Source\PlayerFile.cs" /> <Compile Include="Source\PlayerFile.cs" />
<Compile Include="Properties\AssemblyInfo.cs" /> <Compile Include="Properties\AssemblyInfo.cs" />
@ -138,7 +143,6 @@
<Compile Include="Source\NBTFile.cs" /> <Compile Include="Source\NBTFile.cs" />
<Compile Include="Source\NBT\JSONSerializer.cs" /> <Compile Include="Source\NBT\JSONSerializer.cs" />
<Compile Include="Source\NBT\NBT.cs" /> <Compile Include="Source\NBT\NBT.cs" />
<Compile Include="Source\NBT\NBTSchema.cs" />
<Compile Include="Source\NBT\NBTVerifier.cs" /> <Compile Include="Source\NBT\NBTVerifier.cs" />
<Compile Include="Source\Player.cs" /> <Compile Include="Source\Player.cs" />
<Compile Include="Source\Region.cs" /> <Compile Include="Source\Region.cs" />
@ -156,6 +160,7 @@
<Compile Include="Source\TileEntityFactory.cs" /> <Compile Include="Source\TileEntityFactory.cs" />
<Compile Include="Source\Utility\Base.cs" /> <Compile Include="Source\Utility\Base.cs" />
<Compile Include="Source\Utility\ByteArray.cs" /> <Compile Include="Source\Utility\ByteArray.cs" />
<Compile Include="Source\Utility\Compat.cs" />
<Compile Include="Source\Utility\IndexedLinkedList.cs" /> <Compile Include="Source\Utility\IndexedLinkedList.cs" />
<Compile Include="Source\Utility\Interface.cs" /> <Compile Include="Source\Utility\Interface.cs" />
<Compile Include="Source\Utility\LRUCache.cs" /> <Compile Include="Source\Utility\LRUCache.cs" />