Version 2.1.0.0

BaseDataReader class

Namespace: Sirenix.Serialization
Assembly: Sirenix.Serialization
public abstract class BaseDataReader : BaseDataReaderWriter, IDataReader, IDisposable
Provides basic functionality and overridable abstract methods for implementing a data reader.

If you inherit this class, it is VERY IMPORTANT that you implement each abstract method to the *exact* specifications the documentation specifies.

Inheritance
See Also

Constructors

BaseDataReader(Stream, DeserializationContext)
Initializes a new instance of the BaseDataReader class.
protected BaseDataReader(Stream stream, DeserializationContext context)
Parameters
System.IO.Stream stream

The base stream of the reader.

DeserializationContext context

The deserialization context to use.

Exceptions
System.ArgumentNullException

The stream or context is null.

System.ArgumentException

Cannot read from stream.

Properties

Context
Gets the deserialization context.
public DeserializationContext Context { get; set; }
CurrentNodeDepth
Gets the current node depth. In other words, the current count of the node stack.
public int CurrentNodeDepth { get; }
CurrentNodeId
Gets the current node id. If this is less than zero, the current node has no id.
public int CurrentNodeId { get; }
CurrentNodeName
Gets the name of the current node.
public string CurrentNodeName { get; }
Stream
Gets or sets the base stream of the reader.
public virtual Stream Stream { get; set; }
Exceptions
System.ArgumentNullException

value

System.ArgumentException

Cannot read from stream

Methods

Dispose()
Disposes all resources and streams kept by the data reader.
public abstract void Dispose()
EnterArray(out Int64)
Tries to enters an array node. This will succeed if the next entry is an StartOfArray.

This call MUST (eventually) be followed by a corresponding call to

This call will change the values of the Sirenix.Serialization.IDataReader.IsInArrayNode, Sirenix.Serialization.IDataReader.CurrentNodeName, Sirenix.Serialization.IDataReader.CurrentNodeId and Sirenix.Serialization.IDataReader.CurrentNodeDepth properties to the correct values for the current array node.

public abstract bool EnterArray(out long length)
Parameters
System.Int64 length

The length of the array that was entered.

Returns
System.Boolean

true if an array was entered, otherwise false

EnterNode(out Type)
Tries to enter a node. This will succeed if the next entry is an StartOfNode.

This call MUST (eventually) be followed by a corresponding call to

This call will change the values of the Sirenix.Serialization.IDataReader.IsInArrayNode, Sirenix.Serialization.IDataReader.CurrentNodeName, Sirenix.Serialization.IDataReader.CurrentNodeId and Sirenix.Serialization.IDataReader.CurrentNodeDepth properties to the correct values for the current node.

public abstract bool EnterNode(out Type type)
Parameters
System.Type type

The type of the node. This value will be null if there was no metadata, or if the reader's serialization binder failed to resolve the type name.

Returns
System.Boolean

true if entering a node succeeded, otherwise false

ExitArray()
Exits the closest array. This method will keep skipping entries using until an EndOfArray is reached, or the end of the stream is reached.

This call MUST have been preceded by a corresponding call to Sirenix.Serialization.IDataReader.EnterArray(System.Int64).

This call will change the values of the Sirenix.Serialization.IDataReader.IsInArrayNode, Sirenix.Serialization.IDataReader.CurrentNodeName, Sirenix.Serialization.IDataReader.CurrentNodeId and Sirenix.Serialization.IDataReader.CurrentNodeDepth to the correct values for the node that was prior to the exited array node.

public abstract bool ExitArray()
Returns
System.Boolean

true if the method exited an array, false if it reached the end of the stream.

ExitNode()
Exits the current node. This method will keep skipping entries using until an EndOfNode is reached, or the end of the stream is reached.

This call MUST have been preceded by a corresponding call to Sirenix.Serialization.IDataReader.EnterNode(System.Type).

This call will change the values of the Sirenix.Serialization.IDataReader.IsInArrayNode, Sirenix.Serialization.IDataReader.CurrentNodeName, Sirenix.Serialization.IDataReader.CurrentNodeId and Sirenix.Serialization.IDataReader.CurrentNodeDepth to the correct values for the node that was prior to the current node.

public abstract bool ExitNode()
Returns
System.Boolean

true if the method exited a node, false if it reached the end of the stream.

GetDataDump()
Gets a dump of the data being read by the writer. The format of this dump varies, but should be useful for debugging purposes.
public abstract string GetDataDump()
Returns
System.String

PeekEntry()
Peeks the current entry.
protected abstract EntryType PeekEntry()
Returns
EntryType

The peeked entry.

PeekEntry(out String)
Peeks ahead and returns the type of the next entry in the stream.
public abstract EntryType PeekEntry(out string name)
Parameters
System.String name

The name of the next entry, if it has one.

Returns
EntryType

The type of the next entry.

PrepareNewSerializationSession()
Tells the reader that a new serialization session is about to begin, and that it should clear all cached values left over from any prior serialization sessions. This method is only relevant when the same reader is used to deserialize several different, unrelated values.
public virtual void PrepareNewSerializationSession()
ReadBoolean(out Boolean)
Reads a System.Boolean value. This call will succeed if the next entry is an Boolean.

If the call fails (and returns false), it will skip the current entry value, unless that entry is an EndOfNode or an EndOfArray.

public abstract bool ReadBoolean(out bool value)
Parameters
System.Boolean value

The value that has been read.

Returns
System.Boolean

true if reading the value succeeded, otherwise false

ReadByte(out Byte)
Reads a System.Byte value. This call will succeed if the next entry is an Integer.

If the value of the stored integer is smaller than System.Byte.MinValue or larger than System.Byte.MaxValue, the result will be default(System.Byte).

If the call fails (and returns false), it will skip the current entry value, unless that entry is an EndOfNode or an EndOfArray.

public abstract bool ReadByte(out byte value)
Parameters
System.Byte value

The value that has been read.

Returns
System.Boolean

true if reading the value succeeded, otherwise false

ReadChar(out Char)
Reads a System.Char value. This call will succeed if the next entry is an String.

If the string of the entry is longer than 1 character, the first character of the string will be taken as the result.

If the call fails (and returns false), it will skip the current entry value, unless that entry is an EndOfNode or an EndOfArray.

public abstract bool ReadChar(out char value)
Parameters
System.Char value

The value that has been read.

Returns
System.Boolean

true if reading the value succeeded, otherwise false

ReadDecimal(out Decimal)
Reads a System.Decimal value. This call will succeed if the next entry is an FloatingPoint or an Integer.

If the stored integer or floating point value is smaller than System.Decimal.MinValue or larger than System.Decimal.MaxValue, the result will be default(System.Decimal).

If the call fails (and returns false), it will skip the current entry value, unless that entry is an EndOfNode or an EndOfArray.

public abstract bool ReadDecimal(out decimal value)
Parameters
System.Decimal value

The value that has been read.

Returns
System.Boolean

true if reading the value succeeded, otherwise false

ReadDouble(out Double)
Reads a System.Double value. This call will succeed if the next entry is an FloatingPoint or an Integer.

If the stored integer or floating point value is smaller than System.Double.MinValue or larger than System.Double.MaxValue, the result will be default(System.Double).

If the call fails (and returns false), it will skip the current entry value, unless that entry is an EndOfNode or an EndOfArray.

public abstract bool ReadDouble(out double value)
Parameters
System.Double value

The value that has been read.

Returns
System.Boolean

true if reading the value succeeded, otherwise false

ReadExternalReference(out Guid)
Reads an external reference guid. This call will succeed if the next entry is an ExternalReferenceByGuid.

If the call fails (and returns false), it will skip the current entry value, unless that entry is an EndOfNode or an EndOfArray.

public abstract bool ReadExternalReference(out Guid guid)
Parameters
System.Guid guid

The external reference guid.

Returns
System.Boolean

true if reading the value succeeded, otherwise false

ReadExternalReference(out Int32)
Reads an external reference index. This call will succeed if the next entry is an ExternalReferenceByIndex.

If the call fails (and returns false), it will skip the current entry value, unless that entry is an EndOfNode or an EndOfArray.

public abstract bool ReadExternalReference(out int index)
Parameters
System.Int32 index

The external reference index.

Returns
System.Boolean

true if reading the value succeeded, otherwise false

ReadExternalReference(out String)
Reads an external reference string. This call will succeed if the next entry is an ExternalReferenceByString.

If the call fails (and returns false), it will skip the current entry value, unless that entry is an EndOfNode or an EndOfArray.

public abstract bool ReadExternalReference(out string id)
Parameters
System.String id

The external reference string.

Returns
System.Boolean

true if reading the value succeeded, otherwise false

ReadGuid(out Guid)
Reads a System.Guid value. This call will succeed if the next entry is an Guid.

If the call fails (and returns false), it will skip the current entry value, unless that entry is an EndOfNode or an EndOfArray.

public abstract bool ReadGuid(out Guid value)
Parameters
System.Guid value

The value that has been read.

Returns
System.Boolean

true if reading the value succeeded, otherwise false

ReadInt16(out Int16)
Reads a System.Int16 value. This call will succeed if the next entry is an Integer.

If the value of the stored integer is smaller than System.Int16.MinValue or larger than System.Int16.MaxValue, the result will be default(System.Int16).

If the call fails (and returns false), it will skip the current entry value, unless that entry is an EndOfNode or an EndOfArray.

public abstract bool ReadInt16(out short value)
Parameters
System.Int16 value

The value that has been read.

Returns
System.Boolean

true if reading the value succeeded, otherwise false

ReadInt32(out Int32)
Reads an System.Int32 value. This call will succeed if the next entry is an Integer.

If the value of the stored integer is smaller than System.Int32.MinValue or larger than System.Int32.MaxValue, the result will be default(System.Int32).

If the call fails (and returns false), it will skip the current entry value, unless that entry is an EndOfNode or an EndOfArray.

public abstract bool ReadInt32(out int value)
Parameters
System.Int32 value

The value that has been read.

Returns
System.Boolean

true if reading the value succeeded, otherwise false

ReadInt64(out Int64)
Reads a System.Int64 value. This call will succeed if the next entry is an Integer.

If the value of the stored integer is smaller than System.Int64.MinValue or larger than System.Int64.MaxValue, the result will be default(System.Int64).

If the call fails (and returns false), it will skip the current entry value, unless that entry is an EndOfNode or an EndOfArray.

public abstract bool ReadInt64(out long value)
Parameters
System.Int64 value

The value that has been read.

Returns
System.Boolean

true if reading the value succeeded, otherwise false

ReadInternalReference(out Int32)
Reads an internal reference id. This call will succeed if the next entry is an InternalReference.

If the call fails (and returns false), it will skip the current entry value, unless that entry is an EndOfNode or an EndOfArray.

public abstract bool ReadInternalReference(out int id)
Parameters
System.Int32 id

The internal reference id.

Returns
System.Boolean

true if reading the value succeeded, otherwise false

ReadNull()
Reads a null value. This call will succeed if the next entry is an Null.

If the call fails (and returns false), it will skip the current entry value, unless that entry is an EndOfNode or an EndOfArray.

public abstract bool ReadNull()
Returns
System.Boolean

true if reading the value succeeded, otherwise false

ReadPrimitiveArray<T>(out T[])
Reads a primitive array value. This call will succeed if the next entry is an PrimitiveArray.

If the call fails (and returns false), it will skip the current entry value, unless that entry is an EndOfNode or an EndOfArray.

public abstract bool ReadPrimitiveArray<T>(out T[] array)
    where T : struct
Parameters
T[] array

The resulting primitive array.

Returns
System.Boolean

true if reading a primitive array succeeded, otherwise false

Type Parameters
T

The element type of the primitive array. Valid element types can be determined using IsPrimitiveArrayType(Type).

ReadSByte(out SByte)
Reads an System.SByte value. This call will succeed if the next entry is an Integer.

If the value of the stored integer is smaller than System.SByte.MinValue or larger than System.SByte.MaxValue, the result will be default(System.SByte).

If the call fails (and returns false), it will skip the current entry value, unless that entry is an EndOfNode or an EndOfArray.

public abstract bool ReadSByte(out sbyte value)
Parameters
System.SByte value

The value that has been read.

Returns
System.Boolean

true if reading the value succeeded, otherwise false

ReadSingle(out Single)
Reads a System.Single value. This call will succeed if the next entry is an FloatingPoint or an Integer.

If the stored integer or floating point value is smaller than System.Single.MinValue or larger than System.Single.MaxValue, the result will be default(System.Single).

If the call fails (and returns false), it will skip the current entry value, unless that entry is an EndOfNode or an EndOfArray.

public abstract bool ReadSingle(out float value)
Parameters
System.Single value

The value that has been read.

Returns
System.Boolean

true if reading the value succeeded, otherwise false

ReadString(out String)
Reads a System.String value. This call will succeed if the next entry is an String.

If the call fails (and returns false), it will skip the current entry value, unless that entry is an EndOfNode or an EndOfArray.

public abstract bool ReadString(out string value)
Parameters
System.String value

The value that has been read.

Returns
System.Boolean

true if reading the value succeeded, otherwise false

ReadToNextEntry()
Consumes the current entry, and reads to the next one.
protected abstract EntryType ReadToNextEntry()
Returns
EntryType

The next entry.

ReadUInt16(out UInt16)
Reads an System.UInt16 value. This call will succeed if the next entry is an Integer.

If the value of the stored integer is smaller than System.UInt16.MinValue or larger than System.UInt16.MaxValue, the result will be default(System.UInt16).

If the call fails (and returns false), it will skip the current entry value, unless that entry is an EndOfNode or an EndOfArray.

public abstract bool ReadUInt16(out ushort value)
Parameters
System.UInt16 value

The value that has been read.

Returns
System.Boolean

true if reading the value succeeded, otherwise false

ReadUInt32(out UInt32)
Reads an System.UInt32 value. This call will succeed if the next entry is an Integer.

If the value of the stored integer is smaller than System.UInt32.MinValue or larger than System.UInt32.MaxValue, the result will be default(System.UInt32).

If the call fails (and returns false), it will skip the current entry value, unless that entry is an EndOfNode or an EndOfArray.

public abstract bool ReadUInt32(out uint value)
Parameters
System.UInt32 value

The value that has been read.

Returns
System.Boolean

true if reading the value succeeded, otherwise false

ReadUInt64(out UInt64)
Reads an System.UInt64 value. This call will succeed if the next entry is an Integer.

If the value of the stored integer is smaller than System.UInt64.MinValue or larger than System.UInt64.MaxValue, the result will be default(System.UInt64).

If the call fails (and returns false), it will skip the current entry value, unless that entry is an EndOfNode or an EndOfArray.

public abstract bool ReadUInt64(out ulong value)
Parameters
System.UInt64 value

The value that has been read.

Returns
System.Boolean

true if reading the value succeeded, otherwise false

SkipEntry()
Skips the next entry value, unless it is an EndOfNode or an EndOfArray. If the next entry value is an StartOfNode or an StartOfArray, all of its contents will be processed, deserialized and registered in the deserialization context, so that internal reference values are not lost to entries further down the stream.
public virtual void SkipEntry()

This website is brand new and built with the Odin 2.1 beta in mind. This means you might discover some features such as attribute expressions that are only available in the beta.

You can download the 2.1 beta from here and read the patch-notes here.