DotNext by .NET Foundation and Contributors

<PackageReference Include="DotNext" Version="4.12.4" />

 BufferHelpers

public static class BufferHelpers
Represents helper methods to work with various buffer representations.
public static string BuildString(this ArrayBufferWriter<char> writer)

Constructs the string from the buffer.

public static void Concat(this ref BufferWriterSlim writer, ReadOnlySpan<string> values)

Writes concatenated strings.

public static ReadOnlySequence<T> Concat<T>(this ReadOnlyMemory<T> first, ReadOnlyMemory<T> second)

Converts two memory blocks to ReadOnlySequence<T> data type.

public static void Concat(this IBufferWriter<char> writer, ReadOnlySpan<string> values)

Writes concatenated strings.

public static void CopyTo<T>(this ref ReadOnlySequence source, Span<T> destination, out int writtenCount)

Copies the contents from the source sequence into a destination span.

public static ref T GetReference<T>(ref MemoryOwner owner)

Gets managed pointer to the first element in the rented memory block.

Reads the value of blittable type from the raw bytes represents by memory block.

public static double ReadDouble(this ref SpanReader reader, bool isLittleEndian)

Decodes double-precision floating-point number.

public static Half ReadHalf(this ref SpanReader reader, bool isLittleEndian)

Decodes half-precision floating-point number.

public static short ReadInt16(this ref SpanReader reader, bool isLittleEndian)

Decodes 16-bit signed integer.

public static int ReadInt32(this ref SpanReader reader, bool isLittleEndian)

Decodes 32-bit signed integer.

public static long ReadInt64(this ref SpanReader reader, bool isLittleEndian)

Decodes 64-bit signed integer.

public static float ReadSingle(this ref SpanReader reader, bool isLittleEndian)

Decodes single-precision floating-point number.

public static ushort ReadUInt16(this ref SpanReader reader, bool isLittleEndian)

Decodes 16-bit unsigned integer.

public static uint ReadUInt32(this ref SpanReader reader, bool isLittleEndian)

Decodes 32-bit unsigned integer.

public static ulong ReadUInt64(this ref SpanReader reader, bool isLittleEndian)

Decodes 64-bit unsigned integer.

public static void ReleaseAll<T>(this ref MemoryOwner owner) where T : IDisposable

Releases all resources encapsulated by the container.

public static void Resize<T>(this ref MemoryOwner owner, int newLength, bool exactSize = true, MemoryAllocator<T> allocator = null)

Resizes the buffer.

public static ReadOnlySequence<T> ToReadOnlySequence<T>(this IEnumerable<ReadOnlyMemory<T>> chunks)

Converts the sequence of memory blocks to ReadOnlySequence<T> data type.

public static ReadOnlySequence<char> ToReadOnlySequence(this IEnumerable<string> strings)

Constructs a sequence of characters from a collection of strings.

public static ReadOnlyMemory<T> TrimLength<T>(this ReadOnlyMemory<T> memory, int maxLength)

Trims the memory block to specified length if it exceeds it. If length is less that maxLength then the original block returned.

public static Memory<T> TrimLength<T>(this Memory<T> memory, int maxLength)

Trims the memory block to specified length if it exceeds it. If length is less that maxLength then the original block returned.

public static bool TryRead<T>(this ref SpanReader reader, out T result) where T : ValueType modreq(System.Runtime.InteropServices.UnmanagedType)

Reads the value of blittable type from the raw bytes represents by memory block.

public static bool TryWrite<T>(this ref SpanWriter writer, ref T value) where T : ValueType modreq(System.Runtime.InteropServices.UnmanagedType)

Writes value of blittable type as bytes to the underlying memory block.

public static void Write(this ref BufferWriterSlim writer, StringBuilder input)

Writes the contents of string builder to the buffer.

public static void Write<T>(this IBufferWriter<T> writer, T value)

Writes single element to the buffer.

public static void Write<T>(this IBufferWriter<T> writer, ref ReadOnlySequence value)

Writes the sequence of elements to the buffer.

public static void Write(this IBufferWriter<char> writer, StringBuilder input)

Writes the contents of string builder to the buffer.

public static void Write<T>(this ref SpanWriter writer, ref T value) where T : ValueType modreq(System.Runtime.InteropServices.UnmanagedType)

Writes value of blittable type as bytes to the underlying memory block.

public static void Write(this ref SpanWriter writer, StringBuilder input)

Writes the contents of a string builder to the buffer.

public static void Write<T>(this ref SpanWriter writer, T value, ReadOnlySpan<char> format = default, IFormatProvider provider = null) where T : ISpanFormattable

Converts the value to a set of characters and writes them to the buffer.

public static int WriteAsString<T>(this ref BufferWriterSlim writer, T value, string format = null, IFormatProvider provider = null)

Writes the value as a string.

public static int WriteAsString<T>(this IBufferWriter<char> writer, T value, string format = null, IFormatProvider provider = null)

Writes the value as a string.

public static void WriteDouble(this ref BufferWriterSlim builder, double value, bool isLittleEndian)

Encodes double-precision floating-point number as bytes.

public static void WriteDouble(this ref SpanWriter writer, double value, bool isLittleEndian)

Writes double-precision floating-point number to the block of memory.

public static int WriteFormattable<T>(this ref BufferWriterSlim writer, T value, ReadOnlySpan<char> format = default, IFormatProvider provider = null) where T : ISpanFormattable

Writes the value as a sequence of characters.

public static void WriteFormattable<T>(this ref BufferWriterSlim writer, T value) where T : IBinaryFormattable<T>

Writes the value as a sequence of bytes.

public static void WriteFormattable<T>(this ref BufferWriterSlim writer, ReadOnlySpan<T> values) where T : IBinaryFormattable<T>

Writes a sequence of formattable values.

public static int WriteFormattable<T>(this IBufferWriter<char> writer, T value, ReadOnlySpan<char> format = default, IFormatProvider provider = null) where T : ISpanFormattable

Converts the value to the characters and write them to the buffer.

public static void WriteFormattable<T>(this IBufferWriter<byte> writer, T value) where T : IBinaryFormattable<T>

Writes the value as a sequence of bytes.

public static void WriteFormattable<T>(this IBufferWriter<byte> writer, ReadOnlySpan<T> values) where T : IBinaryFormattable<T>

Writes a sequence of formattable values.

public static void WriteHalf(this ref BufferWriterSlim builder, Half value, bool isLittleEndian)

Encodes half-precision floating-point number as bytes.

public static void WriteHalf(this ref SpanWriter writer, Half value, bool isLittleEndian)

Writes half-precision floating-point number to the block of memory.

public static void WriteInt16(this ref BufferWriterSlim builder, short value, bool isLittleEndian)

Encodes 16-bit signed integer as bytes.

public static void WriteInt16(this ref SpanWriter writer, short value, bool isLittleEndian)

Writes 16-bit signed integer to the block of memory.

public static void WriteInt32(this ref BufferWriterSlim builder, int value, bool isLittleEndian)

Encodes 32-bit signed integer as bytes.

public static void WriteInt32(this ref SpanWriter writer, int value, bool isLittleEndian)

Writes 32-bit signed integer to the block of memory.

public static void WriteInt64(this ref BufferWriterSlim builder, long value, bool isLittleEndian)

Encodes 64-bit signed integer as bytes.

public static void WriteInt64(this ref SpanWriter writer, long value, bool isLittleEndian)

Writes 64-bit signed integer to the block of memory.

public static void WriteLine(this ref BufferWriterSlim writer)

Writes line termination symbols to the buffer.

public static void WriteLine(this ref BufferWriterSlim writer, ReadOnlySpan<char> characters)

Writes a string to the buffer, followed by a line terminator.

public static void WriteLine(this IBufferWriter<char> writer)

Writes line termination symbols to the buffer.

public static void WriteLine(this IBufferWriter<char> writer, ReadOnlySpan<char> characters)

Writes a string to the buffer, followed by a line terminator.

public static void WriteSingle(this ref BufferWriterSlim builder, float value, bool isLittleEndian)

Encodes single-precision floating-point number as bytes.

public static void WriteSingle(this ref SpanWriter writer, float value, bool isLittleEndian)

Writes single-precision floating-point number to the block of memory.

public static int WriteString(this ref BufferWriterSlim writer, IFormatProvider provider, ref BufferWriterSlimInterpolatedStringHandler handler)

Writes interpolated string to the buffer.

public static int WriteString(this ref BufferWriterSlim writer, ref BufferWriterSlimInterpolatedStringHandler handler)

Writes interpolated string to the buffer.

public static int WriteString(this IBufferWriter<char> writer, IFormatProvider provider, ref BufferWriterInterpolatedStringHandler handler)

Writes interpolated string to the buffer.

public static int WriteString(this IBufferWriter<char> writer, ref BufferWriterInterpolatedStringHandler handler)

Writes interpolated string to the buffer.

public static void WriteUInt16(this ref BufferWriterSlim builder, ushort value, bool isLittleEndian)

Encodes 16-bit unsigned integer as bytes.

public static void WriteUInt16(this ref SpanWriter writer, ushort value, bool isLittleEndian)

Writes 16-bit unsigned integer to the block of memory.

public static void WriteUInt32(this ref BufferWriterSlim builder, uint value, bool isLittleEndian)

Encodes 32-bit unsigned integer as bytes.

public static void WriteUInt32(this ref SpanWriter writer, uint value, bool isLittleEndian)

Writes 32-bit unsigned integer to the block of memory.

public static void WriteUInt64(this ref BufferWriterSlim builder, ulong value, bool isLittleEndian)

Encodes 64-bit unsigned integer as bytes.

public static void WriteUInt64(this ref SpanWriter writer, ulong value, bool isLittleEndian)

Writes 64-bit unsigned integer to the block of memory.