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(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. |
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. |
Encode(IBufferWriter<byte>, ReadOnlySpan<char>, in EncodingContext, LengthFormat?)
Encodes string using the specified encoding.
Declaration
public static long 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 |
---|---|
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(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. |
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. |
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. |