Photon Fusion 2.0.6

Static Public Member Functions | List of all members
BinUtils Class Reference

Utility class for binary data. More...

Static Public Member Functions

static T * AsPointer< T > (this Span< byte > source)
 Returns a pointer to a value of type T from the given byte span. More...
 
static T * AsPointer< T > (this Span< int > source)
 Returns a pointer to a value of type T from the given int span. More...
 
static ref T AsRef< T > (this Span< byte > source)
 Returns a managed pointer to a value of type T. More...
 
static ref T AsRef< T > (this Span< int > source)
 Returns a managed pointer to a value of type T. More...
 
static unsafe String BytesToHex (byte *buffer, int length, int columns=16, string rowSeparator="\n", string columnSeparator=" ")
 Converts a buffer of bytes to a hexadecimal string representation. More...
 
static unsafe string BytesToHex (byte[] buffer, int columns=16)
 Converts a byte array to its hexadecimal string representation. More...
 
static unsafe string BytesToHex (ReadOnlySpan< byte > buffer, int columns=16)
 Converts a byte array to its hexadecimal string representation. More...
 
static string ByteToHex (byte value)
 Converts a byte value to its hexadecimal string representation. More...
 
static unsafe int HexToBytes (string str, byte *buffer, int length)
 Converts a hexadecimal string to a byte array. More...
 
static T Read< T > (this Span< byte > source)
 Reads a value of type T from the given byte span. More...
 
static T Read< T > (this Span< int > source)
 Reads a value of type T from the given int span. More...
 
static unsafe (int, int) HexToInts(string str
 Converts a hexadecimal string to an array of 32-bit integers. More...
 
static unsafe string WordsToHex (int *buffer, int length, int columns=4, string rowSeparator="\n", string columnSeparator=" ")
 Converts a buffer of 32-bit integers to a hexadecimal string representation. More...
 
static string WordsToHex (ReadOnlySpan< int > buffer, int columns=4, string rowSeparator="\n", string columnSeparator=" ")
 Converts a buffer of 32-bit integers to a hexadecimal string representation. More...
 
static unsafe string WordsToHex (ReadOnlySpan< uint > buffer, int columns=4, string rowSeparator="\n", string columnSeparator=" ")
 Converts a buffer of 32-bit unsigned integers to a hexadecimal string representation. More...
 
static unsafe string WordsToHex (uint *buffer, int length, int columns=4, string rowSeparator="\n", string columnSeparator=" ")
 Converts a buffer of 32-bit unsigned integers to a hexadecimal string representation. More...
 

Detailed Description

Utility class for binary data.

Member Function Documentation

◆ AsPointer< T >() [1/2]

static T* AsPointer< T > ( this Span< byte >  source)
static

Returns a pointer to a value of type T from the given byte span.

Template Parameters
TThe type of the value to point to.
Parameters
sourceThe span of bytes to get the pointer from.
Returns
A pointer to the value of type T.
Type Constraints
T :unmanaged 

◆ AsPointer< T >() [2/2]

static T* AsPointer< T > ( this Span< int >  source)
static

Returns a pointer to a value of type T from the given int span.

Template Parameters
TThe type of the value to point to.
Parameters
sourceThe span of ints to get the pointer from.
Returns
A pointer to the value of type T.
Type Constraints
T :unmanaged 

◆ AsRef< T >() [1/2]

static ref T AsRef< T > ( this Span< byte >  source)
static

Returns a managed pointer to a value of type T.

Type Constraints
T :unmanaged 

◆ AsRef< T >() [2/2]

static ref T AsRef< T > ( this Span< int >  source)
static

Returns a managed pointer to a value of type T.

Type Constraints
T :unmanaged 

◆ BytesToHex() [1/3]

static unsafe String BytesToHex ( byte *  buffer,
int  length,
int  columns = 16,
string  rowSeparator = "\n",
string  columnSeparator = " " 
)
static

Converts a buffer of bytes to a hexadecimal string representation.

Parameters
bufferA pointer to the buffer containing the bytes to convert.
lengthThe number of bytes in the buffer.
columnsThe number of columns to format the output. Default is 16.
rowSeparatorThe string to use as a row separator. Default is newline.
columnSeparatorThe string to use as a column separator. Default is a space.
Returns
A string representing the hexadecimal values of the bytes in the buffer.

◆ BytesToHex() [2/3]

static unsafe string BytesToHex ( byte[]  buffer,
int  columns = 16 
)
static

Converts a byte array to its hexadecimal string representation.

Parameters
bufferThe byte array to convert.
columnsThe number of columns to format the output. Default is 16.
Returns
A string representing the hexadecimal values of the bytes in the array.

◆ BytesToHex() [3/3]

static unsafe string BytesToHex ( ReadOnlySpan< byte >  buffer,
int  columns = 16 
)
static

Converts a byte array to its hexadecimal string representation.

Parameters
bufferThe byte array to convert.
columnsThe number of columns to format the output. Default is 16.
Returns
A string representing the hexadecimal values of the bytes in the array.

◆ ByteToHex()

static string ByteToHex ( byte  value)
static

Converts a byte value to its hexadecimal string representation.

Parameters
valueThe byte value to convert.
Returns
A string representing the hexadecimal value of the byte.

◆ HexToBytes()

static unsafe int HexToBytes ( string  str,
byte *  buffer,
int  length 
)
static

Converts a hexadecimal string to a byte array.

Parameters
strThe hexadecimal string to convert.
bufferA pointer to the buffer where the bytes will be stored.
lengthThe maximum number of bytes to store in the buffer.
Returns
The number of characters processed from the input string.

◆ Read< T >() [1/2]

static T Read< T > ( this Span< byte >  source)
static

Reads a value of type T from the given byte span.

Template Parameters
TThe type of the value to read.
Parameters
sourceThe span of bytes to read from.
Returns
The value of type T read from the span.
Type Constraints
T :unmanaged 

◆ Read< T >() [2/2]

static T Read< T > ( this Span< int >  source)
static

Reads a value of type T from the given int span.

Template Parameters
TThe type of the value to read.
Parameters
sourceThe span of ints to read from.
Returns
The value of type T read from the span.
Type Constraints
T :unmanaged 

◆ unsafe()

static unsafe ( int  ,
int   
)
static

Converts a hexadecimal string to an array of 32-bit integers.

Parameters
strThe hexadecimal string to convert.
bufferA pointer to the buffer where the 32-bit integers will be stored.
lengthThe maximum number of 32-bit integers to store in the buffer.
Returns
A tuple containing the number of characters processed from the input string and the number of 32-bit integers stored in the buffer.

◆ WordsToHex() [1/4]

static unsafe string WordsToHex ( int *  buffer,
int  length,
int  columns = 4,
string  rowSeparator = "\n",
string  columnSeparator = " " 
)
static

Converts a buffer of 32-bit integers to a hexadecimal string representation.

Parameters
bufferA pointer to the buffer containing the 32-bit integers to convert.
lengthThe number of 32-bit integers in the buffer.
columnsThe number of columns to format the output. Default is 4.
rowSeparatorThe string to use as a row separator. Default is newline.
columnSeparatorThe string to use as a column separator. Default is a space.
Returns
A string representing the hexadecimal values of the 32-bit integers in the buffer.

◆ WordsToHex() [2/4]

static string WordsToHex ( ReadOnlySpan< int >  buffer,
int  columns = 4,
string  rowSeparator = "\n",
string  columnSeparator = " " 
)
static

Converts a buffer of 32-bit integers to a hexadecimal string representation.

◆ WordsToHex() [3/4]

static unsafe string WordsToHex ( ReadOnlySpan< uint >  buffer,
int  columns = 4,
string  rowSeparator = "\n",
string  columnSeparator = " " 
)
static

Converts a buffer of 32-bit unsigned integers to a hexadecimal string representation.

◆ WordsToHex() [4/4]

static unsafe string WordsToHex ( uint *  buffer,
int  length,
int  columns = 4,
string  rowSeparator = "\n",
string  columnSeparator = " " 
)
static

Converts a buffer of 32-bit unsigned integers to a hexadecimal string representation.

Parameters
bufferA pointer to the buffer containing the 32-bit unsigned integers to convert.
lengthThe number of 32-bit unsigned integers in the buffer.
columnsThe number of columns to format the output. Default is 4.
rowSeparatorThe string to use as a row separator. Default is newline.
columnSeparatorThe string to use as a column separator. Default is a space.
Returns
A string representing the hexadecimal values of the 32-bit unsigned integers in the buffer.