C# Class NewTOAPIA.BufferChunk

Inheritance: IDisposable, ICloneable
ファイルを表示 Open project: Wiladams/NewTOAPIA Class Usage Examples

Private Properties

Property Type Description
BufferChunk System
ValidateIntPtr void
ValidateNonNegative void
ValidateNotZeroLength void
ValidateObject void
ValidatePointerData void
ValidateSufficientData void
ValidateSufficientSpace void
_GetFloat float
_GetInt16 Int16
_GetInt32 Int32
_GetUInt64 UInt64
_SetFloat void
_SetInt16 void
_SetInt32 void
_SetUInt64 void

Public Methods

Method Description
BufferChunk ( byte buffer ) : System

Constructor, create a BufferChunk using an existing byte[] without performing a memcopy

BufferChunk ( byte buffer, int index, int length ) : System

Constructor, create a BufferChunk from its constituent parts

BufferChunk ( int size ) : System

Constructor, create a new BufferChunk and allocate a new byte[] to hold the data.

Clear ( ) : void

Used to zero out the data area of the BufferChunk.

Clone ( ) : object

Creates a shallow copy (new Index and Length, duplicate reference to the same Buffer) of a BufferChunk.

Compare ( byte obj1, byte obj2 ) : bool
Copy ( byte source ) : byte[]
CopyFrom ( IntPtr source, Int32 alength ) : void
CopyTo ( BufferChunk destination, int index ) : void

Copy the valid data section of 'this' to the destination BufferChunk overwriting dest's previous contents This method does not allow dest's valid data section to grow or shrink (i.e. treat valid data as a fixed buffer)

CopyTo ( IntPtr destination, Int32 length ) : void
Dispose ( ) : void

Disposes the internal state of the object

GetByte ( int index ) : byte

Retrieves 1 byte from inside the BufferChunk This method is included for consistency. It simply forwards to the indexer.

GetDouble ( int index ) : double
GetFloat ( int index ) : float
GetInt16 ( int index ) : Int16

Retrieves 2 bytes inside the BufferChunk

GetInt32 ( int index ) : int

Retrieves 4 bytes inside the BufferChunk

GetInt64 ( int index ) : long

Retrieves 8 bytes inside the BufferChunk

GetPaddedUInt16 ( int index ) : UInt16
GetPaddedUInt32 ( int index ) : UInt32
GetPaddedUInt64 ( int index ) : UInt64
GetUInt16 ( int index ) : UInt16

Retrieves 2 bytes inside the BufferChunk

GetUInt32 ( int index ) : UInt32

Retrieves 4 bytes inside the BufferChunk

GetUInt64 ( int index ) : UInt64

Retrieves 8 bytes inside the BufferChunk

GetUTF8String ( int index, int length ) : string

Retrieves length bytes from inside the BufferChunk and converts from UTF8 string

NextBufferChunk ( int length ) : BufferChunk

Returns a BufferChunk consisting of the next 'length' bytes of the BufferChunk instance. Automatically increments Index and decrements Length. This function is useful for iterative functions that parse through a large BufferChunk returning smaller BufferChunks

NextBufferChunkMax ( int length ) : BufferChunk

Returns the requested amount of data, or whatever remains if length > this.length

NextByte ( ) : byte
NextDouble ( ) : double
NextFloat ( ) : float
NextInt16 ( ) : Int16
NextInt32 ( ) : Int32
NextInt64 ( ) : Int64
NextUInt16 ( ) : UInt16
NextUInt32 ( ) : UInt32
NextUInt64 ( ) : UInt64
NextUtf8String ( int length ) : string
Peek ( int index, int length ) : BufferChunk

Create a return BufferChunk containing a subset of the data from the valid data.

Reset ( ) : void

Reset the BufferChunk's Index and Length pointers to zero so it is ready for reuse as an empty BufferChunk. Note that the actual byte[] buffer is not reset, so the memory is not deallocated/reallocated, allowing for more efficient reuse of memory without abusing the GC

Reset ( int index, int length ) : void

Reset the BufferChunk's Index and Length pointers to supplied values

SetByte ( int index, byte data ) : void

Modifies 1 byte inside the BufferChunk This method is included for consistency. It simply forwards to the indexer.

SetInt16 ( int index, Int16 data ) : void

Modifies 2 bytes inside the BufferChunk

SetInt32 ( int index, Int32 data ) : void

Modifies 4 bytes inside the BufferChunk

SetInt64 ( int index, Int64 data ) : void

Modifies 8 bytes inside the BufferChunk

SetPaddedUInt16 ( int index, UInt16 data ) : void
SetPaddedUInt32 ( int index, UInt32 data ) : void
SetPaddedUInt64 ( int index, UInt64 data ) : void
SetUInt16 ( int index, UInt16 data ) : void

Modifies 2 bytes inside the BufferChunk

SetUInt32 ( int index, UInt32 data ) : void

Modifies 4 bytes inside the BufferChunk

SetUInt64 ( int index, UInt64 data ) : void

Modifies 8 bytes inside the BufferChunk

SetUTF8String ( int index, string data ) : void

Modifies UTF8.GetBytes(data) bytes inside the BufferChunk

operator ( ) : BufferChunk

Override + and += operator to allow appending of buffers, provided there is room in the left-most BufferChunk

this ( int index ) : byte

Indexer used to allow us to treat a BufferChunk like a byte[]. Useful when making in place modifications or reads from a BufferChunk.

Private Methods

Method Description
BufferChunk ( ) : System
ValidateIntPtr ( IntPtr ptr ) : void
ValidateNonNegative ( int val ) : void
ValidateNotZeroLength ( int length ) : void
ValidateObject ( object o ) : void
ValidatePointerData ( int index, int length, int dataLength ) : void
ValidateSufficientData ( int requested, int actual ) : void
ValidateSufficientSpace ( int requested, int actual ) : void
_GetFloat ( int index ) : float
_GetInt16 ( int index ) : Int16
_GetInt32 ( int index ) : Int32
_GetUInt64 ( int index ) : UInt64
_SetFloat ( int index, float data ) : void
_SetInt16 ( int index, Int16 data ) : void
_SetInt32 ( int index, Int32 data ) : void
_SetUInt64 ( int index, UInt64 data ) : void

Method Details

BufferChunk() public method

Constructor, create a BufferChunk using an existing byte[] without performing a memcopy
public BufferChunk ( byte buffer ) : System
buffer byte byte[] to be used as the data store for the BufferChunk, /// cannot be null or zero length
return System

BufferChunk() public method

Constructor, create a BufferChunk from its constituent parts
public BufferChunk ( byte buffer, int index, int length ) : System
buffer byte byte[] to be used as the data store for the BufferChunk
index int offset at which the valid data starts
length int amount of 'valid data'
return System

BufferChunk() public method

Constructor, create a new BufferChunk and allocate a new byte[] to hold the data.
public BufferChunk ( int size ) : System
size int int size of the new byte[] to create, must be >= 1
return System

Clear() public method

Used to zero out the data area of the BufferChunk.
public Clear ( ) : void
return void

Clone() public method

Creates a shallow copy (new Index and Length, duplicate reference to the same Buffer) of a BufferChunk.
public Clone ( ) : object
return object

Compare() public static method

public static Compare ( byte obj1, byte obj2 ) : bool
obj1 byte
obj2 byte
return bool

Copy() public static method

public static Copy ( byte source ) : byte[]
source byte
return byte[]

CopyFrom() public method

public CopyFrom ( IntPtr source, Int32 alength ) : void
source System.IntPtr
alength System.Int32
return void

CopyTo() public method

Copy the valid data section of 'this' to the destination BufferChunk overwriting dest's previous contents This method does not allow dest's valid data section to grow or shrink (i.e. treat valid data as a fixed buffer)
public CopyTo ( BufferChunk destination, int index ) : void
destination BufferChunk BufferChunk
index int offset in the destination BufferChunk's valid data
return void

CopyTo() public method

public CopyTo ( IntPtr destination, Int32 length ) : void
destination IntPtr
length Int32
return void

Dispose() public method

Disposes the internal state of the object
public Dispose ( ) : void
return void

GetByte() public method

Retrieves 1 byte from inside the BufferChunk This method is included for consistency. It simply forwards to the indexer.
public GetByte ( int index ) : byte
index int Offset into the valid data
return byte

GetDouble() public method

public GetDouble ( int index ) : double
index int
return double

GetFloat() public method

public GetFloat ( int index ) : float
index int
return float

GetInt16() public method

Retrieves 2 bytes inside the BufferChunk
public GetInt16 ( int index ) : Int16
index int Offset into the valid data
return Int16

GetInt32() public method

Retrieves 4 bytes inside the BufferChunk
public GetInt32 ( int index ) : int
index int Offset into the valid data
return int

GetInt64() public method

Retrieves 8 bytes inside the BufferChunk
public GetInt64 ( int index ) : long
index int Offset into the valid data
return long

GetPaddedUInt16() public method

public GetPaddedUInt16 ( int index ) : UInt16
index int
return UInt16

GetPaddedUInt32() public method

public GetPaddedUInt32 ( int index ) : UInt32
index int
return UInt32

GetPaddedUInt64() public method

public GetPaddedUInt64 ( int index ) : UInt64
index int
return UInt64

GetUInt16() public method

Retrieves 2 bytes inside the BufferChunk
public GetUInt16 ( int index ) : UInt16
index int Offset into the valid data
return UInt16

GetUInt32() public method

Retrieves 4 bytes inside the BufferChunk
public GetUInt32 ( int index ) : UInt32
index int Offset into the valid data
return UInt32

GetUInt64() public method

Retrieves 8 bytes inside the BufferChunk
public GetUInt64 ( int index ) : UInt64
index int Offset into the valid data
return UInt64

GetUTF8String() public method

Retrieves length bytes from inside the BufferChunk and converts from UTF8 string
public GetUTF8String ( int index, int length ) : string
index int Offset into the valid data
length int
return string

NextBufferChunk() public method

Returns a BufferChunk consisting of the next 'length' bytes of the BufferChunk instance. Automatically increments Index and decrements Length. This function is useful for iterative functions that parse through a large BufferChunk returning smaller BufferChunks
public NextBufferChunk ( int length ) : BufferChunk
length int int
return BufferChunk

NextBufferChunkMax() public method

Returns the requested amount of data, or whatever remains if length > this.length
public NextBufferChunkMax ( int length ) : BufferChunk
length int
return BufferChunk

NextByte() public method

public NextByte ( ) : byte
return byte

NextDouble() public method

public NextDouble ( ) : double
return double

NextFloat() public method

public NextFloat ( ) : float
return float

NextInt16() public method

public NextInt16 ( ) : Int16
return Int16

NextInt32() public method

public NextInt32 ( ) : Int32
return Int32

NextInt64() public method

public NextInt64 ( ) : Int64
return Int64

NextUInt16() public method

public NextUInt16 ( ) : UInt16
return UInt16

NextUInt32() public method

public NextUInt32 ( ) : UInt32
return UInt32

NextUInt64() public method

public NextUInt64 ( ) : UInt64
return UInt64

NextUtf8String() public method

public NextUtf8String ( int length ) : string
length int
return string

Peek() public method

Create a return BufferChunk containing a subset of the data from the valid data.
public Peek ( int index, int length ) : BufferChunk
index int int index into the valid data area
length int int length of the data to copy
return BufferChunk

Reset() public method

Reset the BufferChunk's Index and Length pointers to zero so it is ready for reuse as an empty BufferChunk. Note that the actual byte[] buffer is not reset, so the memory is not deallocated/reallocated, allowing for more efficient reuse of memory without abusing the GC
public Reset ( ) : void
return void

Reset() public method

Reset the BufferChunk's Index and Length pointers to supplied values
public Reset ( int index, int length ) : void
index int
length int
return void

SetByte() public method

Modifies 1 byte inside the BufferChunk This method is included for consistency. It simply forwards to the indexer.
public SetByte ( int index, byte data ) : void
index int Offset into the valid data
data byte Value to write at index
return void

SetInt16() public method

Modifies 2 bytes inside the BufferChunk
public SetInt16 ( int index, Int16 data ) : void
index int Offset into the valid data
data Int16 Value to write at index
return void

SetInt32() public method

Modifies 4 bytes inside the BufferChunk
public SetInt32 ( int index, Int32 data ) : void
index int Offset into the valid data
data Int32 Value to write at index
return void

SetInt64() public method

Modifies 8 bytes inside the BufferChunk
public SetInt64 ( int index, Int64 data ) : void
index int Offset into the valid data
data Int64 Value to write at index
return void

SetPaddedUInt16() public method

public SetPaddedUInt16 ( int index, UInt16 data ) : void
index int
data UInt16
return void

SetPaddedUInt32() public method

public SetPaddedUInt32 ( int index, UInt32 data ) : void
index int
data UInt32
return void

SetPaddedUInt64() public method

public SetPaddedUInt64 ( int index, UInt64 data ) : void
index int
data UInt64
return void

SetUInt16() public method

Modifies 2 bytes inside the BufferChunk
public SetUInt16 ( int index, UInt16 data ) : void
index int Offset into the valid data
data UInt16 Value to write at index
return void

SetUInt32() public method

Modifies 4 bytes inside the BufferChunk
public SetUInt32 ( int index, UInt32 data ) : void
index int Offset into the valid data
data UInt32 Value to write at index
return void

SetUInt64() public method

Modifies 8 bytes inside the BufferChunk
public SetUInt64 ( int index, UInt64 data ) : void
index int Offset into the valid data
data UInt64 Value to write at index
return void

SetUTF8String() public method

Modifies UTF8.GetBytes(data) bytes inside the BufferChunk
public SetUTF8String ( int index, string data ) : void
index int Offset into the valid data
data string Value to write at index
return void

operator() public static method

Override + and += operator to allow appending of buffers, provided there is room in the left-most BufferChunk
public static operator ( ) : BufferChunk
return BufferChunk

this() public method

Indexer used to allow us to treat a BufferChunk like a byte[]. Useful when making in place modifications or reads from a BufferChunk.
public this ( int index ) : byte
index int
return byte