Class DataReader
Operates as a buffered data reader for network and file input.
Inherited Members
Namespace: MBNCSUtil
Assembly: MBNCSUtil.dll
Syntax
public class DataReader
Remarks
This class does not write data in any manner; for writing or sending data, use the DataBuffer or derived classes.
This class always uses little-endian byte ordering.
Constructors
| Improve this Doc View SourceDataReader(Byte[])
Creates a new data reader with the specified byte data.
Declaration
public DataReader(byte[] data)
Parameters
Type | Name | Description |
---|---|---|
System.Byte[] | data | The data to read. |
DataReader(Stream, Int32)
Creates a new data reader with the specified stream as input.
Declaration
public DataReader(Stream str, int length)
Parameters
Type | Name | Description |
---|---|---|
System.IO.Stream | str | The stream from which to read. |
System.Int32 | length | The length of the data to read from the stream. |
Remarks
This constructor will block until a full packet has been returned.
Properties
| Improve this Doc View SourceData
Gets a copy of the data used by the current instance. When overridden in a derived class, allows this class to access an alternative data source.
Declaration
protected virtual byte[] Data { get; }
Property Value
Type | Description |
---|---|
System.Byte[] |
Length
Gets the length of the data.
Declaration
public virtual int Length { get; }
Property Value
Type | Description |
---|---|
System.Int32 |
Methods
| Improve this Doc View SourcePeek()
Reads the next byte in the stream but does not consume it.
Declaration
public int Peek()
Returns
Type | Description |
---|---|
System.Int32 | A byte value (0-255) if the call succeeded, or else -1 if reading past the end of the stream. |
PeekDwordString(Byte)
Peeks at the next possible four-byte string with the specified byte padding without advancing the index.
Declaration
public string PeekDwordString(byte padding)
Parameters
Type | Name | Description |
---|---|---|
System.Byte | padding | The byte used to pad the string to total four bytes. |
Returns
Type | Description |
---|---|
System.String | The next 4-byte string, reversed, from the stream. |
ReadBoolean()
Reads a boolean value from the data stream.
Declaration
public bool ReadBoolean()
Returns
Type | Description |
---|---|
System.Boolean | The next boolean value from the data stream. |
Remarks
This method interprets a 32-bit value from the stream as false if it is zero and true if it is nonzero.
ReadByte()
Reads a byte value from the data stream.
Declaration
public byte ReadByte()
Returns
Type | Description |
---|---|
System.Byte | The next byte from the data stream. |
ReadByteArray(Int32)
Reads a byte array from the data stream.
Declaration
public byte[] ReadByteArray(int expectedItems)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | expectedItems | The number of bytes to read from the stream. |
Returns
Type | Description |
---|---|
System.Byte[] | The next expectedItems bytes from the stream. |
ReadCString()
Reads the next C-style ASCII null-terminated string from the stream.
Declaration
public string ReadCString()
Returns
Type | Description |
---|---|
System.String | The next C-style string. |
ReadCString(Encoding)
Reads the next C-style null-terminated string from the stream.
Declaration
public string ReadCString(Encoding enc)
Parameters
Type | Name | Description |
---|---|---|
System.Text.Encoding | enc | The encoding used for the string. |
Returns
Type | Description |
---|---|
System.String | The next C-style string encoded with the specified encoding. |
ReadData()
Reads all remaining data from the stream.
Declaration
public byte[] ReadData()
Returns
Type | Description |
---|---|
System.Byte[] | All remaining data in the stream. |
ReadDwordString(Byte)
Reads the next possible four-byte string with the specified byte padding.
Declaration
public string ReadDwordString(byte padding)
Parameters
Type | Name | Description |
---|---|---|
System.Byte | padding | The byte used to pad the string to total four bytes. |
Returns
Type | Description |
---|---|
System.String | The next 4-byte string, reversed, from the stream. |
ReadInt16()
Reads a signed 16-bit value from the data stream.
Declaration
public short ReadInt16()
Returns
Type | Description |
---|---|
System.Int16 | The next 16-bit value from the data stream. |
ReadInt16Array(Int32)
Reads an array of signed 16-bit values from the data stream.
Declaration
public short[] ReadInt16Array(int expectedItems)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | expectedItems | The number of 16-bit values to read from the stream. |
Returns
Type | Description |
---|---|
System.Int16[] | The next expectedItems 16-bit values from the stream. |
ReadInt32()
Reads a signed 32-bit value from the data stream.
Declaration
public int ReadInt32()
Returns
Type | Description |
---|---|
System.Int32 | The next 32-bit value from the data stream. |
ReadInt32Array(Int32)
Reads an array of signed 32-bit values from the data stream.
Declaration
public int[] ReadInt32Array(int expectedItems)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | expectedItems | The number of 32-bit values to read from the stream. |
Returns
Type | Description |
---|---|
System.Int32[] | The next expectedItems 32-bit values from the stream. |
ReadInt64()
Reads a signed 64-bit value from the data stream.
Declaration
public long ReadInt64()
Returns
Type | Description |
---|---|
System.Int64 | The next 64-bit value from the data stream. |
ReadInt64Array(Int32)
Reads an array of signed 64-bit values from the data stream.
Declaration
public long[] ReadInt64Array(int expectedItems)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | expectedItems | The number of 64-bit values to read from the stream. |
Returns
Type | Description |
---|---|
System.Int64[] | The next expectedItems 64-bit values from the stream. |
ReadNullTerminatedByteArray()
Reads a null-terminated byte array from the data stream.
Declaration
public byte[] ReadNullTerminatedByteArray()
Returns
Type | Description |
---|---|
System.Byte[] | The next byte array in the stream, terminated by a value of 0. |
Remarks
The return value includes the null terminator.
ReadPascalString()
Reads the next pascal-style ASCII string from the stream.
Declaration
public string ReadPascalString()
Returns
Type | Description |
---|---|
System.String | The next pascal-style string. |
ReadPascalString(Encoding)
Reads the next pascal-style string from the stream.
Declaration
public string ReadPascalString(Encoding enc)
Parameters
Type | Name | Description |
---|---|---|
System.Text.Encoding | enc | The encoding used for the string. |
Returns
Type | Description |
---|---|
System.String | The next pascal-style string encoded with the specified encoding. |
ReadTerminatedString(Char, Encoding)
Returns the next variable-length string with the specified terminator character.
Declaration
public string ReadTerminatedString(char Terminator, Encoding enc)
Parameters
Type | Name | Description |
---|---|---|
System.Char | Terminator | The terminator that should indicate the end of the string. |
System.Text.Encoding | enc | The encoding to use to read the string. |
Returns
Type | Description |
---|---|
System.String | A variable-length string with no NULL (0) characters nor the terminator character. |
ReadUInt16()
Reads an unsigned 16-bit value from the data stream.
Declaration
[CLSCompliant(false)]
public ushort ReadUInt16()
Returns
Type | Description |
---|---|
System.UInt16 | The next 16-bit value from the data stream. |
Remarks
This method is not CLS-compliant.
ReadUInt16Array(Int32)
Reads an array of unsigned 16-bit values from the data stream.
Declaration
[CLSCompliant(false)]
public ushort[] ReadUInt16Array(int expectedItems)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | expectedItems | The number of 16-bit values to read from the stream. |
Returns
Type | Description |
---|---|
System.UInt16[] | The next expectedItems 16-bit values from the stream. |
Remarks
This method is not CLS-compliant.
ReadUInt32()
Reads an unsigned 32-bit value from the data stream.
Declaration
[CLSCompliant(false)]
public uint ReadUInt32()
Returns
Type | Description |
---|---|
System.UInt32 | The next 32-bit value from the data stream. |
Remarks
This method is not CLS-compliant.
ReadUInt32Array(Int32)
Reads an array of signed 32-bit values from the data stream.
Declaration
[CLSCompliant(false)]
public uint[] ReadUInt32Array(int expectedItems)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | expectedItems | The number of 32-bit values to read from the stream. |
Returns
Type | Description |
---|---|
System.UInt32[] | The next expectedItems 32-bit values from the stream. |
Remarks
This method is not CLS-compliant.
ReadUInt64()
Reads an unsigned 64-bit value from the data stream.
Declaration
[CLSCompliant(false)]
public ulong ReadUInt64()
Returns
Type | Description |
---|---|
System.UInt64 | The next 64-bit value from the data stream. |
Remarks
This method is not CLS-compliant.
ReadUInt64Array(Int32)
Reads an array of unsigned 64-bit values from the data stream.
Declaration
[CLSCompliant(false)]
public ulong[] ReadUInt64Array(int expectedItems)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | expectedItems | The number of 64-bit values to read from the stream. |
Returns
Type | Description |
---|---|
System.UInt64[] | The next expectedItems 64-bit values from the stream. |
Remarks
This method is not CLS-compliant.
ReadWidePascalString()
Reads the next wide-pascal-style string from the stream.
Declaration
public string ReadWidePascalString()
Returns
Type | Description |
---|---|
System.String | The next wide-pascal-style string. |
ReadWidePascalString(Encoding)
Reads the next wide-pascal-style string from the stream.
Declaration
public string ReadWidePascalString(Encoding enc)
Parameters
Type | Name | Description |
---|---|---|
System.Text.Encoding | enc | The encoding used for the string. |
Returns
Type | Description |
---|---|
System.String | The next wide-pascal-style string encoded with the specified encoding. |
Seek(Int32)
Checks to see whether the offset from the current position lies within the stream and, if so, advances to that position relative to the current location.
Declaration
public bool Seek(int offset)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | offset | The number of bytes beyond the current position to advance to. |
Returns
Type | Description |
---|---|
System.Boolean | True if the position lies within the stream and the cursor was advanced; otherwise false. |
ToString()
Gets a hex representation of this buffer.
Declaration
public override string ToString()
Returns
Type | Description |
---|---|
System.String | A string representing this buffer's contents in hexadecimal notation. |