Class BufferWriter
Represents extension methods for writing typed data into buffer.
Inherited Members
Namespace: DotNext.Buffers
Assembly: DotNext.IO.dll
Syntax
public static class BufferWriter
Methods
| Edit this page View SourceEncode(IBufferWriter<byte>, ReadOnlySpan<char>, in EncodingContext, LengthFormat?)
Encodes string using the specified encoding.
Declaration
public static long Encode(this IBufferWriter<byte> writer, ReadOnlySpan<char> value, in EncodingContext context, LengthFormat? lengthFormat = null)
Parameters
Type | Name | Description |
---|---|---|
IBufferWriter<byte> | writer | The buffer writer. |
ReadOnlySpan<char> | value | 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 |
---|---|
long | The number of written bytes. |
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 : notnull, 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. |
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 : notnull, 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 |
|
Interpolate(IBufferWriter<byte>, in EncodingContext, Span<char>, in EncodingInterpolatedStringHandler)
Encodes formattable string as a sequence of bytes.
Declaration
public static int Interpolate(this IBufferWriter<byte> writer, in EncodingContext context, Span<char> buffer, in EncodingInterpolatedStringHandler handler)
Parameters
Type | Name | Description |
---|---|---|
IBufferWriter<byte> | writer | The output buffer. |
EncodingContext | context | The encoding context. |
Span<char> | buffer | The preallocated buffer to be used for placing characters during encoding. |
EncodingInterpolatedStringHandler | handler | The interpolated string handler. |
Returns
Type | Description |
---|---|
int | The number of produced bytes. |
Interpolate(IBufferWriter<byte>, in EncodingContext, Span<char>, IFormatProvider?, in EncodingInterpolatedStringHandler)
Encodes formattable string as a sequence of bytes.
Declaration
public static int Interpolate(this IBufferWriter<byte> writer, in EncodingContext context, Span<char> buffer, IFormatProvider? provider, in EncodingInterpolatedStringHandler handler)
Parameters
Type | Name | Description |
---|---|---|
IBufferWriter<byte> | writer | The output buffer. |
EncodingContext | context | The encoding context. |
Span<char> | buffer | The preallocated buffer to be used for placing characters during encoding. |
IFormatProvider | provider | The format provider. |
EncodingInterpolatedStringHandler | handler | The interpolated string handler. |
Returns
Type | Description |
---|---|
int | The number of produced bytes. |
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. |