KS.Reactor.ksFixedDataWriter Class Reference

A class that writes uint or struct to a byte array. More...

Static Public Member Functions

static int WriteEncodedUInt (byte[] output, int spaceAvailable, int offset, uint value)
 Write a uint as an encoded value. More...
 
static int WriteData< T > (byte[] output, int spaceAvailable, int offset, T data)
 Write data to a byte array. More...
 

Static Public Attributes

const uint ENCODE_1BYTE = 127
 
const uint ENCODE_2BYTE = 16383
 
const uint ENCODE_4BYTE = 1073741823
 

Detailed Description

A class that writes uint or struct to a byte array.

Member Function Documentation

◆ WriteData< T >()

static int KS.Reactor.ksFixedDataWriter.WriteData< T > ( byte[]  output,
int  spaceAvailable,
int  offset,
data 
)
static

Write data to a byte array.

Template Parameters
TType of data to write.
Parameters
outputOutput byte array.
spaceAvailableAmount of space available for writing.
offsetOffset to begin writing at.
dataData to write.
Returns
Number of bytes written, or -1 on an error.
Type Constraints
T :struct 

◆ WriteEncodedUInt()

static int KS.Reactor.ksFixedDataWriter.WriteEncodedUInt ( byte[]  output,
int  spaceAvailable,
int  offset,
uint  value 
)
static

Write a uint as an encoded value.

This value must be less than 2^30 The lowest bit positions of the encoded value signal the number of bytes to read. If the value is less than or equal to 2^7-1, the first bit is a 0 and the value is placed in bits 1 to 7. If the value is less than or equal to 2^14-1, the first two bits are 01 and the value is placed in bits 2 to 15. If the value is less than or equal to 2^30-1, the first two bits are 11 and the value is placed in bits 2 to 31.

Parameters
outputOutput byte array.
spaceAvailableAmount of space available for writing.
offsetOffset to begin writing at.
valueValue to write.
Returns
Number of bytes written, or -1 on an error