Class DataReader
Binary DataReader for DataStreams.
public class DataReader
- Inheritance
-
DataReader
- Inherited Members
Constructors
DataReader(Stream)
Initializes a new instance of the DataReader class.
public DataReader(Stream stream)
Parameters
stream
StreamStream to read from.
Remarks
By default the endianness is LittleEndian and the encoding is UTF-8.
Properties
DefaultEncoding
Gets or sets the default encoding.
public Encoding DefaultEncoding { get; set; }
Property Value
Endianness
Gets or sets the endianness.
public EndiannessMode Endianness { get; set; }
Property Value
Stream
Gets the stream.
public DataStream Stream { get; }
Property Value
Methods
ReadByType(Type)
Reads a field by type.
public object ReadByType(Type type)
Parameters
type
TypeType of the field.
Returns
- object
The field.
Remarks
Nullable types are not supported.
ReadByte()
Reads a 8-bit byte number.
public byte ReadByte()
Returns
- byte
The next byte.
ReadBytes(int)
Reads bytes from the stream.
public byte[] ReadBytes(int count)
Parameters
count
intNumber of bytes to read.
Returns
- byte[]
The bytes read.
ReadChar(Encoding?)
Reads a char.
public char ReadChar(Encoding? encoding = null)
Parameters
encoding
EncodingEncoding to use or
null
to use DefaultEncoding.
Returns
- char
The next char.
Remarks
This method read one code units. A code unit may not represent a full grapheme. This method may return corrupted code units and may advance a wrong number of bytes if the given number of code units to read are not enough to represent a grapheme.
ReadChars(int, Encoding?)
Reads an array of chars.
public char[] ReadChars(int count, Encoding? encoding = null)
Parameters
count
intThe number of chars (code-units) to read.
encoding
EncodingEncoding to use or
null
to use DefaultEncoding.
Returns
- char[]
The chars (code-units) read.
Remarks
This method reads code units. A code unit may not represent a full grapheme. This method may return corrupted code units and may advance a wrong number of bytes if the given number of code units to read are not enough to represent a grapheme.
ReadDouble()
Reads a 64-bits IEEE 754 double precision floating-point number.
public double ReadDouble()
Returns
- double
The next double number.
ReadInt16()
Reads a signed 16-bit number.
public short ReadInt16()
Returns
- short
The next signed 16-bit number.
ReadInt24()
Reads a 24-bit number.
public int ReadInt24()
Returns
- int
The next 24-bit number.
ReadInt32()
Reads a signed 32-bit number.
public int ReadInt32()
Returns
- int
The next signed 32-bit number.
ReadInt64()
Reads a signed 64-bit number.
public long ReadInt64()
Returns
- long
The next signed 64-bit number.
ReadSByte()
Reads a signed 8-bit byte number.
[CLSCompliant(false)]
public sbyte ReadSByte()
Returns
- sbyte
The next signed byte.
ReadSingle()
Reads a 32-bits IEEE 754 single precision floating-point number.
public float ReadSingle()
Returns
- float
The next float number.
ReadString(int, Encoding?)
Reads a string with a constant size.
public string ReadString(int bytesCount, Encoding? encoding = null)
Parameters
Returns
- string
The string.
ReadString(Encoding?)
Reads a string that ends with the null terminator.
public string ReadString(Encoding? encoding = null)
Parameters
encoding
EncodingOptional encoding to use.
Returns
- string
The string.
ReadString(Type, Encoding?)
Reads the size with a size field first.
public string ReadString(Type sizeType, Encoding? encoding = null)
Parameters
Returns
- string
The string.
ReadStringToToken(string, Encoding?)
Reads a string until a string token is found.
public string ReadStringToToken(string token, Encoding? encoding = null)
Parameters
token
stringToken to find.
encoding
EncodingEncoding to use or
null
to use DefaultEncoding.
Returns
- string
The read string.
ReadUInt16()
Reads an unsigned 16-bit number.
[CLSCompliant(false)]
public ushort ReadUInt16()
Returns
- ushort
The next 16-bit number.
ReadUInt32()
Reads an unsigned 32-bit number.
[CLSCompliant(false)]
public uint ReadUInt32()
Returns
- uint
The next unsigned 32-bit number.
ReadUInt64()
Reads an unsigned 64-bit number.
[CLSCompliant(false)]
public ulong ReadUInt64()
Returns
- ulong
The next unsigned 64-bit number.
Read<T>()
Read a field by type.
public object Read<T>()
Returns
- object
The field.
Type Parameters
T
The type of the field.
SkipPadding(int)
Skip bytes to pad the position in the stream.
public void SkipPadding(int padding)
Parameters
padding
intPadding value.