C# Class GSF.IO.BinaryStreamBase

An abstract class for reading/writing to a little endian stream.
Inheritance: IDisposable
Mostra file Open project: GridProtectionAlliance/openHistorian Class Usage Examples

Public Properties

Property Type Description
Stream BinaryStreamStream
Utf8 System.Text.Encoding

Public Methods

Method Description
Copy ( long source, long destination, int length ) : void

Copies a specified number of bytes to a new location

Dispose ( ) : void

Releases all the resources used by the BinaryStreamBase object.

Flush ( ) : void

When overridden in a derived class, clears all buffers for this stream and causes any buffered data to be written to the underlying device.

InsertBytes ( int numberOfBytes, int lengthOfValidDataToShift ) : void

Inserts a certain number of bytes into the stream, shifting valid data to the right. The stream's position remains unchanged. (ie. pointing to the beginning of the newly inserted bytes).

Internally this fuction merely acomplishes an Array.Copy(stream,position,stream,position+numberOfBytes,lengthOfValidDataToShift) However, it's much more complicated than this. So this is a pretty useful function. The newly created space is uninitialized.

Read ( byte buffer, int offset, int count ) : int

When overridden in a derived class, reads a sequence of bytes from the current stream and advances the position within the stream by the number of bytes read.

Read7BitUInt32 ( ) : uint

Reads from the underlying stream in little endian format. Advancing the position.

Read7BitUInt64 ( ) : ulong

Reads from the underlying stream in little endian format. Advancing the position.

ReadAll ( byte buffer, int length ) : void

Reads from the underlying stream in little endian format. Advancing the position.

ReadAll ( byte buffer, int position, int length ) : void

Reads all of the provided bytes. Will not return prematurely, but continue to execute a Read command until the entire length has been read.

ReadBoolean ( ) : bool

Reads from the underlying stream in little endian format. Advancing the position.

ReadBytes ( ) : byte[]

Reads from the underlying stream in little endian format. Advancing the position.

ReadBytes ( int count ) : byte[]

Reads from the underlying stream in little endian format. Advancing the position.

ReadDateTime ( ) : System.DateTime

Reads from the underlying stream in little endian format. Advancing the position.

ReadDecimal ( ) : decimal

Reads from the underlying stream in little endian format. Advancing the position.

ReadDouble ( ) : double

Reads from the underlying stream in little endian format. Advancing the position.

ReadGuid ( ) : System.Guid

Reads from the underlying stream in little endian format. Advancing the position.

ReadInt16 ( ) : short

Reads from the underlying stream in little endian format. Advancing the position.

ReadInt32 ( ) : int

Reads from the underlying stream in little endian format. Advancing the position.

ReadInt64 ( ) : long

Reads from the underlying stream in little endian format. Advancing the position.

ReadInt8 ( ) : sbyte

Reads from the underlying stream in little endian format. Advancing the position.

ReadSingle ( ) : float

Reads from the underlying stream in little endian format. Advancing the position.

ReadString ( ) : string

Reads from the underlying stream in little endian format. Advancing the position.

ReadUInt ( int bytes ) : ulong

Reads from the underlying stream in little endian format. Advancing the position.

ReadUInt16 ( ) : ushort

Reads from the underlying stream in little endian format. Advancing the position.

ReadUInt24 ( ) : uint

Reads from the underlying stream in little endian format. Advancing the position.

ReadUInt32 ( ) : uint

Reads from the underlying stream in little endian format. Advancing the position.

ReadUInt40 ( ) : ulong

Reads from the underlying stream in little endian format. Advancing the position.

ReadUInt48 ( ) : ulong

Reads from the underlying stream in little endian format. Advancing the position.

ReadUInt56 ( ) : ulong

Reads from the underlying stream in little endian format. Advancing the position.

ReadUInt64 ( ) : ulong

Reads from the underlying stream in little endian format. Advancing the position.

ReadUInt8 ( ) : byte

Reads from the underlying stream in little endian format. Advancing the position.

RemoveBytes ( int numberOfBytes, int lengthOfValidDataToShift ) : void

Removes a certain number of bytes from the stream, shifting valid data after this location to the left. The stream's position remains unchanged. (ie. pointing to where the data used to exist).

Internally this fuction merely acomplishes an Array.Copy(stream,position+numberOfBytes,stream,position,lengthOfValidDataToShift) However, it's much more complicated than this. So this is a pretty useful function. The space at the end of the copy is uninitialized.

Seek ( long offset, SeekOrigin origin ) : long

When overridden in a derived class, sets the position within the current stream.

SetLength ( long value ) : void

When overridden in a derived class, sets the length of the current stream.

TryReadBytes ( int maxLength, byte &value ) : bool

Reads a byte array from the provided stream. If the size of the stream exceedes maxLength value is set to null and this function returns false.

This method can be used to limit the byte size returned. Since an untrusted source could claim that the length is int.MaxValue, this prevents allocating 2GB of RAM to store the result.

TryReadString ( int maxLength, string &value ) : bool

Reads a string from the provided stream. If the size of the string exceedes maxLength value is set to null and this function returns false.

This method can be used to limit the byte size returned. Since an untrusted source could claim that the length is int.MaxValue, this prevents allocating 2GB of RAM to store the result.

UpdateLocalBuffer ( bool isWriting ) : void

Updates the local buffer data.

Write ( System.DateTime value ) : void

Writes the specifed value to the underlying stream in little-endian format.

Write ( System.Guid value ) : void

Writes the specifed value to the underlying stream in little-endian format.

Write ( bool value ) : void

Writes the specifed value to the underlying stream in little-endian format.

Write ( byte value ) : void

Writes the specifed value to the underlying stream in little-endian format.

Write ( byte buffer, int length ) : void

Writes the specifed buffer to the underlying stream in little-endian format.

Write ( byte buffer, int offset, int count ) : void

When overridden in a derived class, writes a sequence of bytes to the current stream and advances the current position within this stream by the number of bytes written.

Write ( decimal value ) : void

Writes the specifed value to the underlying stream in little-endian format.

Write ( double value ) : void

Writes the specifed value to the underlying stream in little-endian format.

Write ( float value ) : void

Writes the specifed value to the underlying stream in little-endian format.

Write ( int value ) : void

Writes the specifed value to the underlying stream in little-endian format.

Write ( long value ) : void

Writes the specifed value to the underlying stream in little-endian format.

Write ( sbyte value ) : void

Writes the specifed value to the underlying stream in little-endian format.

Write ( short value ) : void

Writes the specifed value to the underlying stream in little-endian format.

Write ( string value ) : void

Writes the specifed value to the underlying stream in little-endian format.

Write ( uint value ) : void

Writes the specifed value to the underlying stream in little-endian format.

Write ( ulong value ) : void

Writes the specifed value to the underlying stream in little-endian format.

Write ( ushort value ) : void

Writes the specifed value to the underlying stream in little-endian format.

Write7Bit ( uint value ) : void

Writes the specifed value to the underlying stream in little-endian format.

Write7Bit ( ulong value ) : void

Writes the specifed value to the underlying stream in little-endian format.

WriteUInt ( ulong value, int bytes ) : void

Writes the specifed value to the underlying stream in little-endian format.

WriteUInt24 ( uint value ) : void

Writes the specifed value to the underlying stream in little-endian format.

WriteUInt40 ( ulong value ) : void

Writes the specifed value to the underlying stream in little-endian format.

WriteUInt48 ( ulong value ) : void

Writes the specifed value to the underlying stream in little-endian format.

WriteUInt56 ( ulong value ) : void

Writes the specifed value to the underlying stream in little-endian format.

WriteWithLength ( byte value ) : void

Writes the specifed value to the underlying stream in little-endian format.

Protected Methods

Method Description
BinaryStreamBase ( ) : System

Creates a BinaryStreamBase

Dispose ( bool disposing ) : void

Releases the unmanaged resources used by the BinaryStreamBase object and optionally releases the managed resources.

Method Details

BinaryStreamBase() protected method

Creates a BinaryStreamBase
protected BinaryStreamBase ( ) : System
return System

Copy() public method

Copies a specified number of bytes to a new location
public Copy ( long source, long destination, int length ) : void
source long
destination long
length int
return void

Dispose() public method

Releases all the resources used by the BinaryStreamBase object.
public Dispose ( ) : void
return void

Dispose() protected method

Releases the unmanaged resources used by the BinaryStreamBase object and optionally releases the managed resources.
protected Dispose ( bool disposing ) : void
disposing bool true to release both managed and unmanaged resources; false to release only unmanaged resources.
return void

Flush() public abstract method

When overridden in a derived class, clears all buffers for this stream and causes any buffered data to be written to the underlying device.
An I/O error occurs.
public abstract Flush ( ) : void
return void

InsertBytes() public method

Inserts a certain number of bytes into the stream, shifting valid data to the right. The stream's position remains unchanged. (ie. pointing to the beginning of the newly inserted bytes).
Internally this fuction merely acomplishes an Array.Copy(stream,position,stream,position+numberOfBytes,lengthOfValidDataToShift) However, it's much more complicated than this. So this is a pretty useful function. The newly created space is uninitialized.
public InsertBytes ( int numberOfBytes, int lengthOfValidDataToShift ) : void
numberOfBytes int The number of bytes to insert
lengthOfValidDataToShift int The number of bytes that will need to be shifted to perform this insert
return void

Read() public abstract method

When overridden in a derived class, reads a sequence of bytes from the current stream and advances the position within the stream by the number of bytes read.
The sum of and is larger than the buffer length. is null. or is negative. An I/O error occurs. The stream does not support reading. Methods were called after the stream was closed.
public abstract Read ( byte buffer, int offset, int count ) : int
buffer byte An array of bytes. When this method returns, the buffer contains the specified byte array with the values between and ( + - 1) replaced by the bytes read from the current source.
offset int The zero-based byte offset in at which to begin storing the data read from the current stream.
count int The maximum number of bytes to be read from the current stream.
return int

Read7BitUInt32() public method

Reads from the underlying stream in little endian format. Advancing the position.
public Read7BitUInt32 ( ) : uint
return uint

Read7BitUInt64() public method

Reads from the underlying stream in little endian format. Advancing the position.
public Read7BitUInt64 ( ) : ulong
return ulong

ReadAll() public method

Reads from the underlying stream in little endian format. Advancing the position.
public ReadAll ( byte buffer, int length ) : void
buffer byte the pointer to write the data to
length int the number of bytes to read
return void

ReadAll() public method

Reads all of the provided bytes. Will not return prematurely, but continue to execute a Read command until the entire length has been read.
occurs if the end of the stream has been reached.
public ReadAll ( byte buffer, int position, int length ) : void
buffer byte
position int
length int
return void

ReadBoolean() public method

Reads from the underlying stream in little endian format. Advancing the position.
public ReadBoolean ( ) : bool
return bool

ReadBytes() public method

Reads from the underlying stream in little endian format. Advancing the position.
public ReadBytes ( ) : byte[]
return byte[]

ReadBytes() public method

Reads from the underlying stream in little endian format. Advancing the position.
public ReadBytes ( int count ) : byte[]
count int the number of bytes to read
return byte[]

ReadDateTime() public method

Reads from the underlying stream in little endian format. Advancing the position.
public ReadDateTime ( ) : System.DateTime
return System.DateTime

ReadDecimal() public method

Reads from the underlying stream in little endian format. Advancing the position.
public ReadDecimal ( ) : decimal
return decimal

ReadDouble() public method

Reads from the underlying stream in little endian format. Advancing the position.
public ReadDouble ( ) : double
return double

ReadGuid() public method

Reads from the underlying stream in little endian format. Advancing the position.
public ReadGuid ( ) : System.Guid
return System.Guid

ReadInt16() public method

Reads from the underlying stream in little endian format. Advancing the position.
public ReadInt16 ( ) : short
return short

ReadInt32() public method

Reads from the underlying stream in little endian format. Advancing the position.
public ReadInt32 ( ) : int
return int

ReadInt64() public method

Reads from the underlying stream in little endian format. Advancing the position.
public ReadInt64 ( ) : long
return long

ReadInt8() public method

Reads from the underlying stream in little endian format. Advancing the position.
public ReadInt8 ( ) : sbyte
return sbyte

ReadSingle() public method

Reads from the underlying stream in little endian format. Advancing the position.
public ReadSingle ( ) : float
return float

ReadString() public method

Reads from the underlying stream in little endian format. Advancing the position.
public ReadString ( ) : string
return string

ReadUInt() public method

Reads from the underlying stream in little endian format. Advancing the position.
public ReadUInt ( int bytes ) : ulong
bytes int the number of bytes in the value
return ulong

ReadUInt16() public method

Reads from the underlying stream in little endian format. Advancing the position.
public ReadUInt16 ( ) : ushort
return ushort

ReadUInt24() public method

Reads from the underlying stream in little endian format. Advancing the position.
public ReadUInt24 ( ) : uint
return uint

ReadUInt32() public method

Reads from the underlying stream in little endian format. Advancing the position.
public ReadUInt32 ( ) : uint
return uint

ReadUInt40() public method

Reads from the underlying stream in little endian format. Advancing the position.
public ReadUInt40 ( ) : ulong
return ulong

ReadUInt48() public method

Reads from the underlying stream in little endian format. Advancing the position.
public ReadUInt48 ( ) : ulong
return ulong

ReadUInt56() public method

Reads from the underlying stream in little endian format. Advancing the position.
public ReadUInt56 ( ) : ulong
return ulong

ReadUInt64() public method

Reads from the underlying stream in little endian format. Advancing the position.
public ReadUInt64 ( ) : ulong
return ulong

ReadUInt8() public method

Reads from the underlying stream in little endian format. Advancing the position.
public ReadUInt8 ( ) : byte
return byte

RemoveBytes() public method

Removes a certain number of bytes from the stream, shifting valid data after this location to the left. The stream's position remains unchanged. (ie. pointing to where the data used to exist).
Internally this fuction merely acomplishes an Array.Copy(stream,position+numberOfBytes,stream,position,lengthOfValidDataToShift) However, it's much more complicated than this. So this is a pretty useful function. The space at the end of the copy is uninitialized.
public RemoveBytes ( int numberOfBytes, int lengthOfValidDataToShift ) : void
numberOfBytes int The distance to shift. Positive means shifting to the right (ie. inserting data) /// Negative means shift to the left (ie. deleteing data)
lengthOfValidDataToShift int The number of bytes that will need to be shifted to perform the remove. /// This only includes the data that is valid after the shift is complete, and not the data that will be removed.
return void

Seek() public method

When overridden in a derived class, sets the position within the current stream.
An I/O error occurs. The stream does not support seeking, such as if the stream is constructed from a pipe or console output. Methods were called after the stream was closed.
public Seek ( long offset, SeekOrigin origin ) : long
offset long A byte offset relative to the parameter.
origin SeekOrigin A value of type indicating the reference point used to obtain the new position.
return long

SetLength() public abstract method

When overridden in a derived class, sets the length of the current stream.
An I/O error occurs. The stream does not support both writing and seeking, such as if the stream is constructed from a pipe or console output. Methods were called after the stream was closed.
public abstract SetLength ( long value ) : void
value long The desired length of the current stream in bytes.
return void

TryReadBytes() public method

Reads a byte array from the provided stream. If the size of the stream exceedes maxLength value is set to null and this function returns false.
This method can be used to limit the byte size returned. Since an untrusted source could claim that the length is int.MaxValue, this prevents allocating 2GB of RAM to store the result.
public TryReadBytes ( int maxLength, byte &value ) : bool
maxLength int
value byte
return bool

TryReadString() public method

Reads a string from the provided stream. If the size of the string exceedes maxLength value is set to null and this function returns false.
This method can be used to limit the byte size returned. Since an untrusted source could claim that the length is int.MaxValue, this prevents allocating 2GB of RAM to store the result.
public TryReadString ( int maxLength, string &value ) : bool
maxLength int The maximum number of characters in the string.
value string an output
return bool

UpdateLocalBuffer() public method

Updates the local buffer data.
public UpdateLocalBuffer ( bool isWriting ) : void
isWriting bool hints to the stream if write access is desired.
return void

Write() public method

Writes the specifed value to the underlying stream in little-endian format.
public Write ( System.DateTime value ) : void
value System.DateTime the value to write
return void

Write() public method

Writes the specifed value to the underlying stream in little-endian format.
public Write ( System.Guid value ) : void
value System.Guid the value to write
return void

Write() public method

Writes the specifed value to the underlying stream in little-endian format.
public Write ( bool value ) : void
value bool the value to write
return void

Write() public method

Writes the specifed value to the underlying stream in little-endian format.
public Write ( byte value ) : void
value byte the value to write
return void

Write() public method

Writes the specifed buffer to the underlying stream in little-endian format.
public Write ( byte buffer, int length ) : void
buffer byte the pointer to the first byte
length int the number of bytes to write
return void

Write() public abstract method

When overridden in a derived class, writes a sequence of bytes to the current stream and advances the current position within this stream by the number of bytes written.
public abstract Write ( byte buffer, int offset, int count ) : void
buffer byte An array of bytes. This method copies bytes from to the current stream.
offset int The zero-based byte offset in at which to begin copying bytes to the current stream.
count int The number of bytes to be written to the current stream.
return void

Write() public method

Writes the specifed value to the underlying stream in little-endian format.
public Write ( decimal value ) : void
value decimal the value to write
return void

Write() public method

Writes the specifed value to the underlying stream in little-endian format.
public Write ( double value ) : void
value double the value to write
return void

Write() public method

Writes the specifed value to the underlying stream in little-endian format.
public Write ( float value ) : void
value float the value to write
return void

Write() public method

Writes the specifed value to the underlying stream in little-endian format.
public Write ( int value ) : void
value int the value to write
return void

Write() public method

Writes the specifed value to the underlying stream in little-endian format.
public Write ( long value ) : void
value long the value to write
return void

Write() public method

Writes the specifed value to the underlying stream in little-endian format.
public Write ( sbyte value ) : void
value sbyte the value to write
return void

Write() public method

Writes the specifed value to the underlying stream in little-endian format.
public Write ( short value ) : void
value short the value to write
return void

Write() public method

Writes the specifed value to the underlying stream in little-endian format.
public Write ( string value ) : void
value string the value to write
return void

Write() public method

Writes the specifed value to the underlying stream in little-endian format.
public Write ( uint value ) : void
value uint the value to write
return void

Write() public method

Writes the specifed value to the underlying stream in little-endian format.
public Write ( ulong value ) : void
value ulong the value to write
return void

Write() public method

Writes the specifed value to the underlying stream in little-endian format.
public Write ( ushort value ) : void
value ushort the value to write
return void

Write7Bit() public method

Writes the specifed value to the underlying stream in little-endian format.
public Write7Bit ( uint value ) : void
value uint the value to write
return void

Write7Bit() public method

Writes the specifed value to the underlying stream in little-endian format.
public Write7Bit ( ulong value ) : void
value ulong the value to write
return void

WriteUInt() public method

Writes the specifed value to the underlying stream in little-endian format.
public WriteUInt ( ulong value, int bytes ) : void
value ulong the value to write
bytes int the number of bytes to write.
return void

WriteUInt24() public method

Writes the specifed value to the underlying stream in little-endian format.
public WriteUInt24 ( uint value ) : void
value uint the value to write
return void

WriteUInt40() public method

Writes the specifed value to the underlying stream in little-endian format.
public WriteUInt40 ( ulong value ) : void
value ulong the value to write
return void

WriteUInt48() public method

Writes the specifed value to the underlying stream in little-endian format.
public WriteUInt48 ( ulong value ) : void
value ulong the value to write
return void

WriteUInt56() public method

Writes the specifed value to the underlying stream in little-endian format.
public WriteUInt56 ( ulong value ) : void
value ulong the value to write
return void

WriteWithLength() public method

Writes the specifed value to the underlying stream in little-endian format.
public WriteWithLength ( byte value ) : void
value byte the value to write
return void

Property Details

Stream public_oe property

A Stream implementation of this BinaryStreamBase
public BinaryStreamStream,GSF.IO Stream
return BinaryStreamStream

Utf8 public_oe static_oe property

A shared instance of UTF8 encoding.
public static Encoding,System.Text Utf8
return System.Text.Encoding