Show / Hide Table of Contents

Class BufferWriter

Represents extension methods for writing typed data into buffer.

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

Methods

View Source

Create(IBufferWriter<byte>)

Creates default implementation of binary writer for the buffer writer.

Declaration
public static IAsyncBinaryWriter Create(IBufferWriter<byte> writer)
Parameters
Type Name Description
IBufferWriter<byte> writer

The buffer writer.

Returns
Type Description
IAsyncBinaryWriter

The binary writer.

Exceptions
Type Condition
ArgumentNullException

writer is null.

View Source

Encode(ref BufferWriterSlim<byte>, scoped ReadOnlySpan<char>, in EncodingContext, LengthFormat?)

Encodes string using the specified encoding.

Declaration
public static int Encode(this ref BufferWriterSlim<byte> writer, scoped ReadOnlySpan<char> chars, in EncodingContext context, LengthFormat? lengthFormat = null)
Parameters
Type Name Description
BufferWriterSlim<byte> writer

The buffer writer.

ReadOnlySpan<char> chars

The sequence of characters.

EncodingContext context

The encoding context.

LengthFormat? lengthFormat

String length encoding format; or null to prevent encoding of string length.

Returns
Type Description
int

The number of written bytes.

View Source

Encode(ref SpanWriter<byte>, scoped ReadOnlySpan<char>, in EncodingContext, LengthFormat?)

Encodes string using the specified encoding.

Declaration
public static int Encode(this ref SpanWriter<byte> writer, scoped ReadOnlySpan<char> chars, in EncodingContext context, LengthFormat? lengthFormat = null)
Parameters
Type Name Description
SpanWriter<byte> writer

The buffer writer.

ReadOnlySpan<char> chars

The sequence of characters.

EncodingContext context

The encoding context.

LengthFormat? lengthFormat

String length encoding format; or null to prevent encoding of string length.

Returns
Type Description
int

The number of written bytes.

View Source

Encode(IBufferWriter<byte>, ReadOnlySpan<char>, in EncodingContext, LengthFormat?)

Encodes string using the specified encoding.

Declaration
public static int Encode(this IBufferWriter<byte> writer, ReadOnlySpan<char> chars, in EncodingContext context, LengthFormat? lengthFormat = null)
Parameters
Type Name Description
IBufferWriter<byte> writer

The buffer writer.

ReadOnlySpan<char> chars

The sequence of characters.

EncodingContext context

The encoding context.

LengthFormat? lengthFormat

String length encoding format; or null to prevent encoding of string length.

Returns
Type Description
int

The number of written bytes.

View Source

Format<T>(IBufferWriter<byte>, T, in EncodingContext, LengthFormat?, ReadOnlySpan<char>, IFormatProvider?, MemoryAllocator<char>?)

Encodes formatted value as a set of characters using the specified encoding.

Declaration
public static long Format<T>(this IBufferWriter<byte> writer, T value, in EncodingContext context, LengthFormat? lengthFormat, ReadOnlySpan<char> format = default, IFormatProvider? provider = null, MemoryAllocator<char>? allocator = null) where T : ISpanFormattable
Parameters
Type Name Description
IBufferWriter<byte> writer

The buffer writer.

T value

The type value to be written as string.

EncodingContext context

The context describing encoding of characters.

LengthFormat? lengthFormat

String length encoding format.

ReadOnlySpan<char> format

The format of the value.

IFormatProvider provider

The format provider.

MemoryAllocator<char> allocator

The allocator of internal buffer of characters.

Returns
Type Description
long

The number of written bytes.

Type Parameters
Name Description
T

The type of formattable value.

View Source

Format<T>(IBufferWriter<byte>, T, LengthFormat?, ReadOnlySpan<char>, IFormatProvider?)

Encodes formatted value as a set of UTF-8 bytes using the specified encoding.

Declaration
public static int Format<T>(this IBufferWriter<byte> writer, T value, LengthFormat? lengthFormat, ReadOnlySpan<char> format = default, IFormatProvider? provider = null) where T : IUtf8SpanFormattable
Parameters
Type Name Description
IBufferWriter<byte> writer

The buffer writer.

T value

The type value to be written as string.

LengthFormat? lengthFormat

String length encoding format.

ReadOnlySpan<char> format

The format of the value.

IFormatProvider provider

The format provider.

Returns
Type Description
int

The number of written bytes.

Type Parameters
Name Description
T

The type of formattable value.

Exceptions
Type Condition
InsufficientMemoryException

writer has not enough free space to place UTF-8 bytes.

View Source

Write(ref BufferWriterSlim<byte>, scoped ReadOnlySpan<byte>, LengthFormat)

Writes a sequence of bytes prefixed with the length.

Declaration
public static int Write(this ref BufferWriterSlim<byte> writer, scoped ReadOnlySpan<byte> value, LengthFormat lengthFormat)
Parameters
Type Name Description
BufferWriterSlim<byte> writer

The buffer writer.

ReadOnlySpan<byte> value

A sequence of bytes to be written.

LengthFormat lengthFormat

A format of the buffer length to be written.

Returns
Type Description
int

A number of bytes written.

View Source

Write(ref SpanWriter<byte>, scoped ReadOnlySpan<byte>, LengthFormat)

Writes a sequence of bytes prefixed with the length.

Declaration
public static int Write(this ref SpanWriter<byte> writer, scoped ReadOnlySpan<byte> value, LengthFormat lengthFormat)
Parameters
Type Name Description
SpanWriter<byte> writer

The buffer writer.

ReadOnlySpan<byte> value

A sequence of bytes to be written.

LengthFormat lengthFormat

A format of the buffer length to be written.

Returns
Type Description
int

A number of bytes written.

View Source

Write<T>(IBufferWriter<T>, in ReadOnlySequence<T>)

Writes the sequence of elements to the buffer.

Declaration
public static void Write<T>(this IBufferWriter<T> writer, in ReadOnlySequence<T> value)
Parameters
Type Name Description
IBufferWriter<T> writer

The buffer writer.

ReadOnlySequence<T> value

The sequence of elements to be written.

Type Parameters
Name Description
T

The type of the elements in the sequence.

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