Class BufferReader
Auto-resizable buffer (similar to MemoryStream) but with methods to read arrays of any simple value type, not just byte[]. This class is typically used in conjunction with BufferWriter.
Namespace: Microsoft.Psi.Common
Assembly: Microsoft.Psi.dll
Syntax
public class BufferReader : object
Constructors
View SourceBufferReader()
Initializes a new instance of the BufferReader class.
Declaration
public BufferReader()
BufferReader(BufferWriter)
Initializes a new instance of the BufferReader class using the buffer already filled in by the specified BufferWriter. Note that the underlying buffer is shared, and the writer could corrupt it.
Declaration
public BufferReader(BufferWriter writer)
Parameters
Type | Name | Description |
---|---|---|
BufferWriter | writer | The writer to share the buffer with. |
BufferReader(Byte[])
Initializes a new instance of the BufferReader class using the specified buffer.
Declaration
public BufferReader(byte[] buffer)
Parameters
Type | Name | Description |
---|---|---|
System.Byte[] | buffer | The buffer to read from. |
BufferReader(Byte[], Int32)
Initializes a new instance of the BufferReader class using the specified buffer.
Declaration
public BufferReader(byte[] buffer, int length)
Parameters
Type | Name | Description |
---|---|---|
System.Byte[] | buffer | The buffer to read from. |
System.Int32 | length | The count of valid bytes in the buffer. |
Properties
View SourceBuffer
Gets the underlying buffer.
Declaration
public byte[] Buffer { get; }
Property Value
Type | Description |
---|---|
System.Byte[] |
Length
Gets the number of valid bytes in the underlying buffer.
Declaration
public int Length { get; }
Property Value
Type | Description |
---|---|
System.Int32 |
Position
Gets the current position of the reader.
Declaration
public int Position { get; }
Property Value
Type | Description |
---|---|
System.Int32 |
RemainingLength
Gets the number of unread bytes.
Declaration
public int RemainingLength { get; }
Property Value
Type | Description |
---|---|
System.Int32 |
Methods
View SourceCopyToStream(Stream, Int32)
Copies the specified number of bytes from the underlying buffer into the specified stream.
Declaration
public void CopyToStream(Stream target, int count)
Parameters
Type | Name | Description |
---|---|---|
Stream | target | The stream to copy to. |
System.Int32 | count | The number of bytes to copy. |
Read(Byte[], Int32)
Copies the specified number of bytes from the underlying buffer into the specified array.
Declaration
public void Read(byte[] target, int count)
Parameters
Type | Name | Description |
---|---|---|
System.Byte[] | target | The array to copy to. |
System.Int32 | count | The number of bytes to copy. |
Read(Char[], Int32)
Copies the specified number of elements of type Char from the underlying buffer into the specified array.
Declaration
public void Read(char[] target, int count)
Parameters
Type | Name | Description |
---|---|---|
System.Char[] | target | The array to copy to. |
System.Int32 | count | The number of elements to copy. |
Read(Double[], Int32)
Copies the specified number of elements of type Double from the underlying buffer into the specified array.
Declaration
public void Read(double[] target, int count)
Parameters
Type | Name | Description |
---|---|---|
System.Double[] | target | The array to copy to. |
System.Int32 | count | The number of elements to copy. |
Read(Int16[], Int32)
Copies the specified number of elements of type Int16 from the underlying buffer into the specified array.
Declaration
public void Read(short[] target, int count)
Parameters
Type | Name | Description |
---|---|---|
System.Int16[] | target | The array to copy to. |
System.Int32 | count | The number of elements to copy. |
Read(Int32[], Int32)
Copies the specified number of elements of type Int32 from the underlying buffer into the specified array.
Declaration
public void Read(int[] target, int count)
Parameters
Type | Name | Description |
---|---|---|
System.Int32[] | target | The array to copy to. |
System.Int32 | count | The number of elements to copy. |
Read(Int64[], Int32)
Copies the specified number of elements of type Int64 from the underlying buffer into the specified array.
Declaration
public void Read(long[] target, int count)
Parameters
Type | Name | Description |
---|---|---|
System.Int64[] | target | The array to copy to. |
System.Int32 | count | The number of elements to copy. |
Read(Single[], Int32)
Copies the specified number of elements of type Single from the underlying buffer into the specified array.
Declaration
public void Read(float[] target, int count)
Parameters
Type | Name | Description |
---|---|---|
Single[] | target | The array to copy to. |
System.Int32 | count | The number of elements to copy. |
Read(UInt16[], Int32)
Copies the specified number of elements of type UInt16 from the underlying buffer into the specified array.
Declaration
public void Read(ushort[] target, int count)
Parameters
Type | Name | Description |
---|---|---|
System.UInt16[] | target | The array to copy to. |
System.Int32 | count | The number of elements to copy. |
Read(Void*, Int32)
Copies the specified number of bytes from the underlying buffer to the specified memory address.
Declaration
public void Read(void *target, int lengthInBytes)
Parameters
Type | Name | Description |
---|---|---|
Void* | target | The target memory address. |
System.Int32 | lengthInBytes | The number of bytes to copy. |
ReadBool()
Reads one Bool value from the underlying buffer.
Declaration
public bool ReadBool()
Returns
Type | Description |
---|---|
System.Boolean | The value read from the buffer. |
ReadByte()
Reads one Byte value from the underlying buffer.
Declaration
public byte ReadByte()
Returns
Type | Description |
---|---|
System.Byte | The value read from the buffer. |
ReadChar()
Reads one Char value from the underlying buffer.
Declaration
public char ReadChar()
Returns
Type | Description |
---|---|
System.Char | The value read from the buffer. |
ReadDateTime()
Reads one DateTime value from the underlying buffer.
Declaration
public DateTime ReadDateTime()
Returns
Type | Description |
---|---|
DateTime | The value read from the buffer. |
ReadDouble()
Reads one Double value from the underlying buffer.
Declaration
public double ReadDouble()
Returns
Type | Description |
---|---|
System.Double | The value read from the buffer. |
ReadEnvelope()
Reads one Envelope value from the underlying buffer.
Declaration
public Envelope ReadEnvelope()
Returns
Type | Description |
---|---|
Envelope | The value read from the buffer. |
ReadInt16()
Reads one Int16 value from the underlying buffer.
Declaration
public short ReadInt16()
Returns
Type | Description |
---|---|
System.Int16 | The value read from the buffer. |
ReadInt32()
Reads one Int32 value from the underlying buffer.
Declaration
public int ReadInt32()
Returns
Type | Description |
---|---|
System.Int32 | The value read from the buffer. |
ReadInt64()
Reads one Int64 value from the underlying buffer.
Declaration
public long ReadInt64()
Returns
Type | Description |
---|---|
System.Int64 | The value read from the buffer. |
ReadSByte()
Reads one SByte value from the underlying buffer.
Declaration
public sbyte ReadSByte()
Returns
Type | Description |
---|---|
SByte | The value read from the buffer. |
ReadSingle()
Reads one Single value from the underlying buffer.
Declaration
public float ReadSingle()
Returns
Type | Description |
---|---|
Single | The value read from the buffer. |
ReadString()
Reads one String value from the underlying buffer.
Declaration
public string ReadString()
Returns
Type | Description |
---|---|
String | The value read from the buffer. |
ReadUInt16()
Reads one UInt16 value from the underlying buffer.
Declaration
public ushort ReadUInt16()
Returns
Type | Description |
---|---|
System.UInt16 | The value read from the buffer. |
ReadUInt32()
Reads one UInt32 value from the underlying buffer.
Declaration
public uint ReadUInt32()
Returns
Type | Description |
---|---|
System.UInt32 | The value read from the buffer. |
ReadUInt64()
Reads one UInt64 value from the underlying buffer.
Declaration
public ulong ReadUInt64()
Returns
Type | Description |
---|---|
System.UInt64 | The value read from the buffer. |
Reset()
Resets the position of the reader to the beginning of the buffer.
Declaration
public void Reset()
Reset(Int32)
Resets the reader to the beginning and resizes the buffer as needed. Note that any data in the buffer is lost.
Declaration
public void Reset(int length)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | length | The new buffer length. |
Seek(Int32)
Moves the current position to the specified place in the underlying buffer.
Declaration
public void Seek(int position)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | position | The position to move the to. |