Version 2.1.0.0

IDataReader interface

Namespace: Sirenix.Serialization
Assembly: Sirenix.Serialization
public interface IDataReader : IDisposable
Provides a set of methods for reading data stored in a format written by a corresponding IDataWriter class.

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

It is strongly recommended to inherit from the BaseDataReader class if you wish to implement a new data reader.

See Also
  • System.IDisposable

Properties

Binder
Gets or sets the reader's serialization binder.
TwoWaySerializationBinder Binder { get; set; }
Context
Gets the deserialization context.
DeserializationContext Context { get; set; }
CurrentNodeDepth
Gets the current node depth. In other words, the current count of the node stack.
int CurrentNodeDepth { get; }
CurrentNodeId
Gets the current node id. If this is less than zero, the current node has no id.
int CurrentNodeId { get; }
CurrentNodeName
Gets the name of the current node.
string CurrentNodeName { get; }
IsInArrayNode
Gets a value indicating whether the reader is in an array node.
bool IsInArrayNode { get; }

Methods

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 IsInArrayNode, CurrentNodeName, CurrentNodeId and CurrentNodeDepth properties to the correct values for the current array node.

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 IsInArrayNode, CurrentNodeName, CurrentNodeId and CurrentNodeDepth properties to the correct values for the current node.

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 EnterArray(out Int64).

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

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 EnterNode(out Type).

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

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.
string GetDataDump()
Returns
System.String

PeekEntry(out String)
Peeks ahead and returns the type of the next entry in the stream.
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.
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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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

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.

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.

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.

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.
void SkipEntry()