Show / Hide Table of Contents

Class ByteBuffer

Providers extension methods to work with byte buffers.

Inheritance
object
ByteBuffer
Inherited Members
object.Equals(object)
object.Equals(object, object)
object.GetHashCode()
object.GetType()
object.MemberwiseClone()
object.ReferenceEquals(object, object)
object.ToString()
Namespace: DotNext.Buffers
Assembly: DotNext.dll
Syntax
public static class ByteBuffer

Methods

| Edit this page View Source

Format<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 : 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

writer has not enough space to place value.

| Edit this page View Source

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 : 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

writer has not enough space to place value.

| Edit this page View Source

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 : IBinaryInteger<T>
Parameters
Type Name Description
SpanReader<byte> reader

The buffer reader.

Returns
Type Description
T

The value read from reader.

Type Parameters
Name Description
T

The integer type.

| Edit this page View Source

ReadLeb128<T>(ref SpanReader<byte>)

Decodes an integer encoded as 7-bit octets.

Declaration
public static T ReadLeb128<T>(this ref SpanReader<byte> reader) where T : struct, IBinaryInteger<T>
Parameters
Type Name Description
SpanReader<byte> reader

The buffer reader.

Returns
Type Description
T

The decoded integer.

Type Parameters
Name Description
T

The integer type.

| Edit this page View Source

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 : IBinaryInteger<T>
Parameters
Type Name Description
SpanReader<byte> reader

The buffer reader.

Returns
Type Description
T

The value read from reader.

Type Parameters
Name Description
T

The integer type.

| Edit this page View Source

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 : 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.

| Edit this page View Source

TryEncodeAsUtf8(ref SpanWriter<byte>, ReadOnlySpan<char>)

Writes the specified sequence of characters as UTF-8 encoded octets.

Declaration
public static bool TryEncodeAsUtf8(this ref SpanWriter<byte> writer, ReadOnlySpan<char> input)
Parameters
Type Name Description
SpanWriter<byte> writer

The buffer writer.

ReadOnlySpan<char> input

The input characters to be encoded.

Returns
Type Description
bool

true if input is encoded successfully; otherwise, false.

| Edit this page View Source

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 : 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 writer has enough space to place formatted value; otherwise, false.

Type Parameters
Name Description
T

The type of the value to be written as UTF-8.

| Edit this page View Source

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 : 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 value is restored successfully; false if reader has not enough bytes to read.

Type Parameters
Name Description
T

The type of value to read.

| Edit this page View Source

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

true to use unsigned encoding; otherwise, false.

bool isUnsigned

true to write the bytes in a big-endian byte order; otherwise, false.

Returns
Type Description
bool

true if writer has enough space to place formatted value; otherwise, false.

| Edit this page View Source

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 : 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 writer has enough space to place formatted value; otherwise, false.

Type Parameters
Name Description
T

The type of the value to be written as a sequence of bytes.

| Edit this page View Source

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

true to use unsigned encoding; otherwise, false.

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

writer has not enough space to place value.

| Edit this page View Source

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

true to use unsigned encoding; otherwise, false.

Returns
Type Description
int

The number of bytes written.

Exceptions
Type Condition
InsufficientMemoryException

writer has not enough space to place value.

| Edit this page View Source

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 : 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

writer has not enough space to place value.

| Edit this page View Source

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 : 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

writer has not enough space to place value.

| Edit this page View Source

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 : 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

writer has not enough space to place value.

| Edit this page View Source

WriteLeb128<T>(ref BufferWriterSlim<byte>, T)

Writes 32-bit integer in a compressed format.

Declaration
public static int WriteLeb128<T>(this ref BufferWriterSlim<byte> writer, T value) where T : struct, IBinaryInteger<T>
Parameters
Type Name Description
BufferWriterSlim<byte> writer

The buffer writer.

T value

The integer to be written.

Returns
Type Description
int

A number of bytes written to the buffer.

Type Parameters
Name Description
T
| Edit this page View Source

WriteLeb128<T>(ref SpanWriter<byte>, T)

Writes 32-bit integer in a compressed format.

Declaration
public static int WriteLeb128<T>(this ref SpanWriter<byte> writer, T value) where T : struct, IBinaryInteger<T>
Parameters
Type Name Description
SpanWriter<byte> writer

The buffer writer.

T value

The integer to be written.

Returns
Type Description
int

A number of bytes written to the buffer.

Type Parameters
Name Description
T
| Edit this page View Source

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 : 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

writer has not enough space to place value.

| Edit this page View Source

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 : 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

writer has not enough space to place value.

| Edit this page View Source

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 : 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

writer has not enough space to place value.

| Edit this page View Source

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 : 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.

| Edit this page View Source

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 : 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.

| Edit this page View Source

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 : 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.

  • Edit this page
  • View Source
☀
☾
In this article
Back to top
Supported by the .NET Foundation
☀
☾