Class ByteBuffer
Providers extension methods to work with byte buffers.
Inherited Members
Namespace: DotNext.Buffers
Assembly: DotNext.dll
Syntax
public static class ByteBuffer
Methods
| Edit this page View SourceFormat<T>(ref BufferWriterSlim<byte>, T, ReadOnlySpan<char>, IFormatProvider?)
Formats the value as UTF-8 into the provided buffer.
Declaration
public static int Format<T>(this ref BufferWriterSlim<byte> writer, T value, ReadOnlySpan<char> format = default, IFormatProvider? provider = null) where T : notnull, IUtf8SpanFormattable
Parameters
Type | Name | Description |
---|---|---|
BufferWriterSlim<byte> | writer | The buffer writer. |
T | value | The value to be written as a sequence of bytes. |
ReadOnlySpan<char> | format | A standard or custom format string. |
IFormatProvider | provider | Culture-specific formatting information. |
Returns
Type | Description |
---|---|
int | The number of bytes written. |
Type Parameters
Name | Description |
---|---|
T | The type of the value to be written as UTF-8. |
Exceptions
Type | Condition |
---|---|
InsufficientMemoryException |
|
Format<T>(IBufferWriter<byte>, T, ReadOnlySpan<char>, IFormatProvider?)
Formats the value as UTF-8 into the provided buffer.
Declaration
public static int Format<T>(this IBufferWriter<byte> writer, T value, ReadOnlySpan<char> format = default, IFormatProvider? provider = null) where T : notnull, IUtf8SpanFormattable
Parameters
Type | Name | Description |
---|---|---|
IBufferWriter<byte> | writer | The buffer writer. |
T | value | The value to be written as a sequence of bytes. |
ReadOnlySpan<char> | format | A standard or custom format string. |
IFormatProvider | provider | Culture-specific formatting information. |
Returns
Type | Description |
---|---|
int | The number of bytes written. |
Type Parameters
Name | Description |
---|---|
T | The type of the value to be written as UTF-8. |
Exceptions
Type | Condition |
---|---|
InsufficientMemoryException |
|
ReadBigEndian<T>(ref SpanReader<byte>)
Reads integer value encoded in big-endian format.
Declaration
public static T ReadBigEndian<T>(this ref SpanReader<byte> reader) where T : notnull, IBinaryInteger<T>
Parameters
Type | Name | Description |
---|---|---|
SpanReader<byte> | reader | The buffer reader. |
Returns
Type | Description |
---|---|
T | The value read from |
Type Parameters
Name | Description |
---|---|
T | The integer type. |
ReadLittleEndian<T>(ref SpanReader<byte>)
Reads integer value encoded in little-endian format.
Declaration
public static T ReadLittleEndian<T>(this ref SpanReader<byte> reader) where T : notnull, IBinaryInteger<T>
Parameters
Type | Name | Description |
---|---|---|
SpanReader<byte> | reader | The buffer reader. |
Returns
Type | Description |
---|---|
T | The value read from |
Type Parameters
Name | Description |
---|---|
T | The integer type. |
Read<T>(ref SpanReader<byte>)
Restores a value from a sequence of bytes.
Declaration
public static T Read<T>(this ref SpanReader<byte> reader) where T : notnull, IBinaryFormattable<T>
Parameters
Type | Name | Description |
---|---|---|
SpanReader<byte> | reader | The buffer reader. |
Returns
Type | Description |
---|---|
T | The value restored from a sequence of bytes. |
Type Parameters
Name | Description |
---|---|
T | The type of value to read. |
TryFormat<T>(ref SpanWriter<byte>, T, ReadOnlySpan<char>, IFormatProvider?)
Tries to format the value as UTF-8 into the provided buffer.
Declaration
public static bool TryFormat<T>(this ref SpanWriter<byte> writer, T value, ReadOnlySpan<char> format = default, IFormatProvider? provider = null) where T : notnull, IUtf8SpanFormattable
Parameters
Type | Name | Description |
---|---|---|
SpanWriter<byte> | writer | The buffer writer. |
T | value | The value to be written as a sequence of bytes. |
ReadOnlySpan<char> | format | A standard or custom format string. |
IFormatProvider | provider | Culture-specific formatting information. |
Returns
Type | Description |
---|---|
bool | true if |
Type Parameters
Name | Description |
---|---|
T | The type of the value to be written as UTF-8. |
TryRead<T>(ref SpanReader<byte>, out T?)
Tries to restore a value from a sequence of bytes.
Declaration
public static bool TryRead<T>(this ref SpanReader<byte> reader, out T? value) where T : notnull, IBinaryFormattable<T>
Parameters
Type | Name | Description |
---|---|---|
SpanReader<byte> | reader | The buffer reader. |
T | value | The value restored from a sequence of bytes. |
Returns
Type | Description |
---|---|
bool | true if |
Type Parameters
Name | Description |
---|---|
T | The type of value to read. |
TryWrite(ref SpanWriter<byte>, in BigInteger, bool, bool)
Writes BigInteger value to the buffer.
Declaration
public static bool TryWrite(this ref SpanWriter<byte> writer, in BigInteger value, bool isBigEndian = false, bool isUnsigned = false)
Parameters
Type | Name | Description |
---|---|---|
SpanWriter<byte> | writer | The buffer writer. |
BigInteger | value | The value to be written as a sequence of bytes. |
bool | isBigEndian | |
bool | isUnsigned | true to write the bytes in a big-endian byte order; otherwise, false. |
Returns
Type | Description |
---|---|
bool | true if |
TryWrite<T>(ref SpanWriter<byte>, T)
Tries to write the value as a sequence of bytes to the buffer.
Declaration
public static bool TryWrite<T>(this ref SpanWriter<byte> writer, T value) where T : notnull, IBinaryFormattable<T>
Parameters
Type | Name | Description |
---|---|---|
SpanWriter<byte> | writer | The buffer writer. |
T | value | The value to be written as a sequence of bytes. |
Returns
Type | Description |
---|---|
bool | true if |
Type Parameters
Name | Description |
---|---|
T | The type of the value to be written as a sequence of bytes. |
Write(ref BufferWriterSlim<byte>, in BigInteger, bool, bool)
Writes BigInteger value to the buffer.
Declaration
public static int Write(this ref BufferWriterSlim<byte> writer, in BigInteger value, bool isBigEndian = false, bool isUnsigned = false)
Parameters
Type | Name | Description |
---|---|---|
BufferWriterSlim<byte> | writer | The buffer writer. |
BigInteger | value | The value to be written as a sequence of bytes. |
bool | isBigEndian | |
bool | isUnsigned | true to write the bytes in a big-endian byte order; otherwise, false. |
Returns
Type | Description |
---|---|
int | The number of bytes written. |
Exceptions
Type | Condition |
---|---|
InsufficientMemoryException |
|
Write(IBufferWriter<byte>, in BigInteger, bool, bool)
Writes BigInteger value to the buffer.
Declaration
public static int Write(this IBufferWriter<byte> writer, in BigInteger value, bool isBigEndian = false, bool isUnsigned = false)
Parameters
Type | Name | Description |
---|---|---|
IBufferWriter<byte> | writer | The buffer writer. |
BigInteger | value | The value to be written as a sequence of bytes. |
bool | isBigEndian | true to write the bytes in a big-endian byte order; otherwise, false. |
bool | isUnsigned |
Returns
Type | Description |
---|---|
int | The number of bytes written. |
Exceptions
Type | Condition |
---|---|
InsufficientMemoryException |
|
WriteBigEndian<T>(ref BufferWriterSlim<byte>, T)
Writes integer in big-endian format.
Declaration
public static int WriteBigEndian<T>(this ref BufferWriterSlim<byte> writer, T value) where T : notnull, IBinaryInteger<T>
Parameters
Type | Name | Description |
---|---|---|
BufferWriterSlim<byte> | writer | The buffer writer. |
T | value | The value to be written in big-endian format. |
Returns
Type | Description |
---|---|
int | The number of bytes written. |
Type Parameters
Name | Description |
---|---|
T | The integer type. |
Exceptions
Type | Condition |
---|---|
InsufficientMemoryException |
|
WriteBigEndian<T>(ref SpanWriter<byte>, T)
Writes integer in big-endian format.
Declaration
public static int WriteBigEndian<T>(this ref SpanWriter<byte> writer, T value) where T : notnull, IBinaryInteger<T>
Parameters
Type | Name | Description |
---|---|---|
SpanWriter<byte> | writer | The buffer writer. |
T | value | The value to be written in big-endian format. |
Returns
Type | Description |
---|---|
int | The number of bytes written. |
Type Parameters
Name | Description |
---|---|
T | The integer type. |
Exceptions
Type | Condition |
---|---|
InsufficientMemoryException |
|
WriteBigEndian<T>(IBufferWriter<byte>, T)
Writes integer in big-endian format.
Declaration
public static int WriteBigEndian<T>(this IBufferWriter<byte> writer, T value) where T : notnull, IBinaryInteger<T>
Parameters
Type | Name | Description |
---|---|---|
IBufferWriter<byte> | writer | The buffer writer. |
T | value | The value to be written in big-endian format. |
Returns
Type | Description |
---|---|
int | The number of bytes written. |
Type Parameters
Name | Description |
---|---|
T | The integer type. |
Exceptions
Type | Condition |
---|---|
InsufficientMemoryException |
|
WriteLittleEndian<T>(ref BufferWriterSlim<byte>, T)
Writes integer in little-endian format.
Declaration
public static int WriteLittleEndian<T>(this ref BufferWriterSlim<byte> writer, T value) where T : notnull, IBinaryInteger<T>
Parameters
Type | Name | Description |
---|---|---|
BufferWriterSlim<byte> | writer | The buffer writer. |
T | value | The value to be written in little-endian format. |
Returns
Type | Description |
---|---|
int | The number of bytes written. |
Type Parameters
Name | Description |
---|---|
T | The integer type. |
Exceptions
Type | Condition |
---|---|
InsufficientMemoryException |
|
WriteLittleEndian<T>(ref SpanWriter<byte>, T)
Writes integer in little-endian format.
Declaration
public static int WriteLittleEndian<T>(this ref SpanWriter<byte> writer, T value) where T : notnull, IBinaryInteger<T>
Parameters
Type | Name | Description |
---|---|---|
SpanWriter<byte> | writer | The buffer writer. |
T | value | The value to be written in little-endian format. |
Returns
Type | Description |
---|---|
int | The number of bytes written. |
Type Parameters
Name | Description |
---|---|
T | The integer type. |
Exceptions
Type | Condition |
---|---|
InsufficientMemoryException |
|
WriteLittleEndian<T>(IBufferWriter<byte>, T)
Writes integer in little-endian format.
Declaration
public static int WriteLittleEndian<T>(this IBufferWriter<byte> writer, T value) where T : notnull, IBinaryInteger<T>
Parameters
Type | Name | Description |
---|---|---|
IBufferWriter<byte> | writer | The buffer writer. |
T | value | The value to be written in little-endian format. |
Returns
Type | Description |
---|---|
int | The number of bytes written. |
Type Parameters
Name | Description |
---|---|
T | The integer type. |
Exceptions
Type | Condition |
---|---|
InsufficientMemoryException |
|
Write<T>(ref BufferWriterSlim<byte>, T)
Writes the value as a sequence of bytes to the buffer.
Declaration
public static void Write<T>(this ref BufferWriterSlim<byte> writer, T value) where T : notnull, IBinaryFormattable<T>
Parameters
Type | Name | Description |
---|---|---|
BufferWriterSlim<byte> | writer | The buffer writer. |
T | value | The value to be written as a sequence of bytes. |
Type Parameters
Name | Description |
---|---|
T | The type of the value to be written as a sequence of bytes. |
Write<T>(ref SpanWriter<byte>, T)
Writes the value as a sequence of bytes to the buffer.
Declaration
public static void Write<T>(this ref SpanWriter<byte> writer, T value) where T : notnull, IBinaryFormattable<T>
Parameters
Type | Name | Description |
---|---|---|
SpanWriter<byte> | writer | The buffer writer. |
T | value | The value to be written as a sequence of bytes. |
Type Parameters
Name | Description |
---|---|
T | The type of the value to be written as a sequence of bytes. |
Write<T>(IBufferWriter<byte>, T)
Writes the value as a sequence of bytes to the buffer.
Declaration
public static void Write<T>(this IBufferWriter<byte> writer, T value) where T : notnull, IBinaryFormattable<T>
Parameters
Type | Name | Description |
---|---|---|
IBufferWriter<byte> | writer | The buffer writer. |
T | value | The value to be written as a sequence of bytes. |
Type Parameters
Name | Description |
---|---|
T | The type of the value to be written as a sequence of bytes. |