KS.Reactor.ksStreamBuffer Class Reference

Manages a buffer for reading and writing stream data toa byte array. More...

Classes

class  Segment
 Represents a segment of a ksStreamBuffer. More...
 

Public Member Functions

void Clear (bool zero=false)
 Clears all data from the buffer. More...
 
void ResizeBuffer (int size)
 Resizes and zeros the used portion of the manage array. More...
 
void Write (byte value)
 Writes a byte value at the current buffer offset. More...
 
void Write (byte[] value)
 Writes a byte array at the current buffer offset. More...
 
void Write< T > (T value)
 Writes a struct at the current buffer offset. More...
 
byte Read ()
 Reads the byte at the current buffer offset. More...
 
byte[] ReadBytes (int count=-1)
 Reads multiple bytes at the current buffer offset. More...
 
Read< T > ()
 Reads the struct at the current buffer offset. More...
 
bool TryGetSegment (out Segment segment, int offset=0, int count=-1)
 Attempts to get a segment of the buffer. More...
 
void Release ()
 Releases the buffer and put it pool of available buffers. More...
 

Static Public Member Functions

static ksStreamBuffer Create ()
 Fetches a ksStreamBuffer from a pool of available buffers or create a new ksStreamBuffer if the pool is empty. More...
 

Properties

byte[] Array [get]
 Byte array managed by the stream buffer. More...
 
int Count [get]
 Amount of data in the managed array used by the buffer. More...
 
int Offset [get, set]
 Current position of the cursor in the buffer. More...
 

Detailed Description

Manages a buffer for reading and writing stream data toa byte array.

Member Function Documentation

◆ Clear()

void KS.Reactor.ksStreamBuffer.Clear ( bool  zero = false)

Clears all data from the buffer.

Parameters
zeroIf this is true, all bytes in the managed array will be set to 0.

◆ Create()

static ksStreamBuffer KS.Reactor.ksStreamBuffer.Create ( )
static

Fetches a ksStreamBuffer from a pool of available buffers or create a new ksStreamBuffer if the pool is empty.

Returns

◆ Read()

byte KS.Reactor.ksStreamBuffer.Read ( )

Reads the byte at the current buffer offset.

Returns

◆ Read< T >()

Reads the struct at the current buffer offset.

Template Parameters
T
Returns
Type Constraints
T :struct 

◆ ReadBytes()

byte [] KS.Reactor.ksStreamBuffer.ReadBytes ( int  count = -1)

Reads multiple bytes at the current buffer offset.

Parameters
countNumber of bytes to read (-1 = up to the end of the buffer).
Returns

◆ Release()

void KS.Reactor.ksStreamBuffer.Release ( )

Releases the buffer and put it pool of available buffers.

◆ ResizeBuffer()

void KS.Reactor.ksStreamBuffer.ResizeBuffer ( int  size)

Resizes and zeros the used portion of the manage array.

Parameters
sizeNew size.

◆ TryGetSegment()

bool KS.Reactor.ksStreamBuffer.TryGetSegment ( out Segment  segment,
int  offset = 0,
int  count = -1 
)

Attempts to get a segment of the buffer.

Parameters
segmentSegement of buffer.
offsetSegment start index.
countSegment size (-1 up to the end of the buffer).
Returns

◆ Write() [1/2]

void KS.Reactor.ksStreamBuffer.Write ( byte  value)

Writes a byte value at the current buffer offset.

Parameters
value

◆ Write() [2/2]

void KS.Reactor.ksStreamBuffer.Write ( byte[]  value)

Writes a byte array at the current buffer offset.

Parameters
value

◆ Write< T >()

void KS.Reactor.ksStreamBuffer.Write< T > ( value)

Writes a struct at the current buffer offset.

Template Parameters
T
Parameters
value
Type Constraints
T :struct 

Property Documentation

◆ Array

byte [] KS.Reactor.ksStreamBuffer.Array
get

Byte array managed by the stream buffer.

Note: active buffers may only be using up to Count bytes of this array.

◆ Count

int KS.Reactor.ksStreamBuffer.Count
get

Amount of data in the managed array used by the buffer.

◆ Offset

int KS.Reactor.ksStreamBuffer.Offset
getset

Current position of the cursor in the buffer.

All read/write operations will access the managed array at this position.