Bny.RawBytes 1.0.0
C# library for reading and writing binary data
Loading...
Searching...
No Matches
Bytes Class Reference

Contains functions for converting from and to byte array More...

Static Public Member Functions

static int From< T > (T? value, Span< byte > result, BytesParam? par=null)
 Converts the value into byte array More...
 
static int From (object? value, Span< byte > result, BytesParam? par=null)
 Converts the value into byte array More...
 
static int TryFrom< T > (T? value, Span< byte > result, BytesParam? par=null)
 Converts the value into byte array More...
 
static int TryFrom (object? value, Span< byte > result, BytesParam? par=null)
 Converts the value into byte array More...
 
static void From< T > (T? value, Stream output, BytesParam? par=null)
 Converts the value into bytes and writes it to a stream More...
 
static void From (object? value, Stream output, BytesParam? par=null)
 Converts the value into bytes and writes it to a stream More...
 
static bool TryFrom< T > (T? value, Stream output, BytesParam? par=null)
 Converts the value into bytes and writes it to a stream More...
 
static bool TryFrom (object? value, Stream output, BytesParam? par=null)
 Converts the value into bytes and writes it to a stream More...
 
static T To< T > (ReadOnlySpan< byte > data, BytesParam? par=null)
 Converts byte array to the given type More...
 
static T To< T > (ReadOnlySpan< byte > data, out int readedBytes, BytesParam? par=null)
 Converts byte array to the given type More...
 
static object To (ReadOnlySpan< byte > data, Type type, BytesParam? par=null)
 Converts byte array to the given type More...
 
static object To (ReadOnlySpan< byte > data, Type type, out int readedBytes, BytesParam? par=null)
 Converts byte array to the given type More...
 
static int TryTo< T > (ReadOnlySpan< byte > data, out T? result, BytesParam? par=null)
 Converts byte array to the given type More...
 
static int TryTo (ReadOnlySpan< byte > data, Type type, out object? result, BytesParam? par=null)
 Converts byte array to the given type More...
 
static T To< T > (Stream data, BytesParam? par=null)
 Reads the given type from the given stream More...
 
static object To (Stream data, Type type, BytesParam? par=null)
 Reads the given type from the given stream More...
 
static bool TryTo< T > (Stream data, [NotNullWhen(true)] out T? result, BytesParam? par=null)
 Reads the given type from the given stream More...
 
static bool TryTo (Stream data, Type type, [NotNullWhen(true)] out object? result, BytesParam? par=null)
 Reads the given type from the given stream More...
 

Static Public Attributes

static readonly Endianness DefaultEndianness
 The default byte order More...
 

Properties

static unsafe bool IsDefaultLE [get]
 Gets the default endianness. Returns true if the Endianness.Default conversion has the same results as Endianness.Little, otherwise returns false.
 

Detailed Description

Contains functions for converting from and to byte array

Member Function Documentation

◆ From() [1/2]

static int Bytes.From ( object?  value,
Span< byte >  result,
BytesParam?  par = null 
)
static

Converts the value into byte array

Parameters
valuevalue to convert
resultWhere the bytes will be written
parthe conversion parameters, null creates default conversion parameters
Returns
number of written bytes
Exceptions
ArgumentExceptionthrown for unsupported types

◆ From() [2/2]

static void Bytes.From ( object?  value,
Stream  output,
BytesParam?  par = null 
)
static

Converts the value into bytes and writes it to a stream

Parameters
valuevylue to convert
outputWhere the bytes will be written
parthe conversion parameters, null creates default conversion parameters
Exceptions
ArgumentExceptionthrown for unsupported types

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

static int Bytes.From< T > ( T?  value,
Span< byte >  result,
BytesParam?  par = null 
)
static

Converts the value into byte array

Template Parameters
TType of the value to convert
Parameters
valuevalue to convert
resultWhere the bytes will be written
parthe conversion parameters, null creates default conversion parameters
Returns
number of written bytes
Exceptions
ArgumentExceptionthrown for unsupported types

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

static void Bytes.From< T > ( T?  value,
Stream  output,
BytesParam?  par = null 
)
static

Converts the value into bytes and writes it to a stream

Template Parameters
TType of the value to convert
Parameters
valuevylue to convert
outputWhere the bytes will be written
parthe conversion parameters, null creates default conversion parameters
Exceptions
ArgumentExceptionthrown for unsupported types

◆ To() [1/3]

static object Bytes.To ( ReadOnlySpan< byte >  data,
Type  type,
BytesParam?  par = null 
)
static

Converts byte array to the given type

Parameters
dataBytes to convert
typeType to convert to
parthe conversion parameters, null creates default conversion parameters
Returns
The byte span converted to the type
Exceptions
ArgumentExceptionThrown for unsuported types

◆ To() [2/3]

static object Bytes.To ( ReadOnlySpan< byte >  data,
Type  type,
out int  readedBytes,
BytesParam?  par = null 
)
static

Converts byte array to the given type

Parameters
dataBytes to convert
typeType to convert to
readedBytesnumber of bytes readed
parthe conversion parameters, null creates default conversion parameters
Returns
The byte span converted to the type
Exceptions
ArgumentExceptionThrown for unsuported types

◆ To() [3/3]

static object Bytes.To ( Stream  data,
Type  type,
BytesParam?  par = null 
)
static

Reads the given type from the given stream

Parameters
dataStream to read from
typetype to convert to
parthe conversion parameters, null creates default conversion parameters
Returns
The byte span converted to the type
Exceptions
ArgumentExceptionT hrown for unsuported types

◆ To< T >() [1/3]

static T Bytes.To< T > ( ReadOnlySpan< byte >  data,
BytesParam?  par = null 
)
static

Converts byte array to the given type

Template Parameters
TType to convert to
Parameters
dataBytes to convert
parthe conversion parameters, null creates default conversion parameters
Returns
The byte span converted to the type

◆ To< T >() [2/3]

static T Bytes.To< T > ( ReadOnlySpan< byte >  data,
out int  readedBytes,
BytesParam?  par = null 
)
static

Converts byte array to the given type

Template Parameters
TType to convert to
Parameters
dataBytes to convert
readedBytesnumber of bytes readed
parthe conversion parameters, null creates default conversion parameters
Returns
The byte span converted to the type

◆ To< T >() [3/3]

static T Bytes.To< T > ( Stream  data,
BytesParam?  par = null 
)
static

Reads the given type from the given stream

Template Parameters
Ttype to convert to
Parameters
dataStream to read from
parthe conversion parameters, null creates default conversion parameters
Returns
The byte span converted to the type
Exceptions
ArgumentExceptionThrown for unsuported types

◆ TryFrom() [1/2]

static int Bytes.TryFrom ( object?  value,
Span< byte >  result,
BytesParam?  par = null 
)
static

Converts the value into byte array

Parameters
valuevalue to convert
resultWhere the bytes will be written
parthe conversion parameters, null creates default conversion parameters
Returns
number of written bytes, -1 on error

◆ TryFrom() [2/2]

static bool Bytes.TryFrom ( object?  value,
Stream  output,
BytesParam?  par = null 
)
static

Converts the value into bytes and writes it to a stream

Parameters
valuevalue to convert
outputWhere the bytes will be written
parthe conversion parameters, null creates default conversion parameters
Returns
true on success, otherwise false

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

static int Bytes.TryFrom< T > ( T?  value,
Span< byte >  result,
BytesParam?  par = null 
)
static

Converts the value into byte array

Template Parameters
TType of the value to convert
Parameters
valuevalue to convert
resultWhere the bytes will be written
parthe conversion parameters, null creates default conversion parameters
Returns
number of written bytes, -1 on error

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

static bool Bytes.TryFrom< T > ( T?  value,
Stream  output,
BytesParam?  par = null 
)
static

Converts the value into bytes and writes it to a stream

Template Parameters
TType of the value to convert
Parameters
valuevalue to convert
outputWhere the bytes will be written
parthe conversion parameters, null creates default conversion parameters
Returns
true on success, otherwise false

◆ TryTo() [1/2]

static int Bytes.TryTo ( ReadOnlySpan< byte >  data,
Type  type,
out object?  result,
BytesParam?  par = null 
)
static

Converts byte array to the given type

Parameters
dataBytes to convert
typeType to convert to
resultthe converted value
parthe conversion parameters, null creates default conversion parameters
Returns
number of readed bytes on success, otherwise negative

◆ TryTo() [2/2]

static bool Bytes.TryTo ( Stream  data,
Type  type,
[NotNullWhen(true)] out object?  result,
BytesParam?  par = null 
)
static

Reads the given type from the given stream

Parameters
dataStream to read from
typeType to convert to
resultResult of the conversion
parthe conversion parameters, null creates default conversion parameters
Returns
true on success, otherwise false

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

static int Bytes.TryTo< T > ( ReadOnlySpan< byte >  data,
out T?  result,
BytesParam?  par = null 
)
static

Converts byte array to the given type

Template Parameters
TType to convert to
Parameters
dataBytes to convert
resultthe result, not null when returns positive
parthe conversion parameters, null creates default conversion parameters
Returns
The byte span converted to the type

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

static bool Bytes.TryTo< T > ( Stream  data,
[NotNullWhen(true)] out T?  result,
BytesParam?  par = null 
)
static

Reads the given type from the given stream

Template Parameters
Ttype to convert to
Parameters
dataStream to read from
resultthe result od the operation
parthe conversion parameters, null creates default conversion parameters
Returns
true on success, otherwise false

Member Data Documentation

◆ DefaultEndianness

readonly Endianness Bytes.DefaultEndianness
static
Initial value:
=
? Endianness.Little
: Endianness.Big
static unsafe bool IsDefaultLE
Gets the default endianness. Returns true if the Endianness.Default conversion has the same results a...
Definition: Bytes.cs:18

The default byte order


The documentation for this class was generated from the following files: