Skip to content

Struct BufferSpan

Namespace: Void.Minecraft.Buffers
Assembly: Void.Minecraft.dll

Manages a span of bytes, allowing access and manipulation of its position within the buffer.

public ref struct BufferSpan : IMinecraftBuffer<BufferSpan>, IReadMinecraftBuffer, IWriteMinecraftBuffer, ICommonMinecraftBuffer, IDisposable

Implements

IMinecraftBuffer<BufferSpan>, IReadMinecraftBuffer, IWriteMinecraftBuffer, ICommonMinecraftBuffer, IDisposable

Inherited Members

object.Equals(object?), object.Equals(object?, object?), object.GetHashCode(), object.GetType(), object.ReferenceEquals(object?, object?), object.ToString()

Extension Methods

ReadMinecraftBufferExtensions.Dump<BufferSpan>(ref BufferSpan), ReadMinecraftBufferExtensions.Read<BufferSpan>(ref BufferSpan, int), ReadMinecraftBufferExtensions.ReadBoolean<BufferSpan>(ref BufferSpan), ReadMinecraftBufferExtensions.ReadByteArray<BufferSpan>(ref BufferSpan), ReadMinecraftBufferExtensions.ReadComponent<BufferSpan>(ref BufferSpan), ReadMinecraftBufferExtensions.ReadDouble<BufferSpan>(ref BufferSpan), ReadMinecraftBufferExtensions.ReadFloat<BufferSpan>(ref BufferSpan), ReadMinecraftBufferExtensions.ReadInt<BufferSpan>(ref BufferSpan), ReadMinecraftBufferExtensions.ReadIntArray<BufferSpan>(ref BufferSpan), ReadMinecraftBufferExtensions.ReadLong<BufferSpan>(ref BufferSpan), ReadMinecraftBufferExtensions.ReadProperty<BufferSpan>(ref BufferSpan), ReadMinecraftBufferExtensions.ReadPropertyArray<BufferSpan>(ref BufferSpan, int), ReadMinecraftBufferExtensions.ReadShort<BufferSpan>(ref BufferSpan), ReadMinecraftBufferExtensions.ReadString<BufferSpan>(ref BufferSpan, int), ReadMinecraftBufferExtensions.ReadTag<BufferSpan>(ref BufferSpan, bool), ReadMinecraftBufferExtensions.ReadToEnd<BufferSpan>(ref BufferSpan), ReadMinecraftBufferExtensions.ReadUnsignedByte<BufferSpan>(ref BufferSpan), ReadMinecraftBufferExtensions.ReadUnsignedShort<BufferSpan>(ref BufferSpan), ReadMinecraftBufferExtensions.ReadUuid<BufferSpan>(ref BufferSpan), ReadMinecraftBufferExtensions.ReadUuidAsIntArray<BufferSpan>(ref BufferSpan), ReadMinecraftBufferExtensions.ReadVarInt<BufferSpan>(ref BufferSpan), ReadMinecraftBufferExtensions.ReadVarIntArray<BufferSpan>(ref BufferSpan), ReadMinecraftBufferExtensions.ReadVarLong<BufferSpan>(ref BufferSpan), ReadMinecraftBufferExtensions.ReadVarShort<BufferSpan>(ref BufferSpan), WriteMinecraftBufferExtensions.Write<BufferSpan>(ref BufferSpan, scoped ReadOnlySpan<byte>), WriteMinecraftBufferExtensions.Write<BufferSpan>(ref BufferSpan, Stream), WriteMinecraftBufferExtensions.WriteBoolean<BufferSpan>(ref BufferSpan, bool), WriteMinecraftBufferExtensions.WriteByteArray<BufferSpan>(ref BufferSpan, scoped ReadOnlySpan<byte>), WriteMinecraftBufferExtensions.WriteComponent<BufferSpan>(ref BufferSpan, Component), WriteMinecraftBufferExtensions.WriteDouble<BufferSpan>(ref BufferSpan, double), WriteMinecraftBufferExtensions.WriteFloat<BufferSpan>(ref BufferSpan, float), WriteMinecraftBufferExtensions.WriteInt<BufferSpan>(ref BufferSpan, int), WriteMinecraftBufferExtensions.WriteIntArray<BufferSpan>(ref BufferSpan, scoped ReadOnlySpan<int>), WriteMinecraftBufferExtensions.WriteLong<BufferSpan>(ref BufferSpan, long), WriteMinecraftBufferExtensions.WriteProperty<BufferSpan>(ref BufferSpan, Property), WriteMinecraftBufferExtensions.WritePropertyArray<BufferSpan>(ref BufferSpan, Property[]?), WriteMinecraftBufferExtensions.WriteShort<BufferSpan>(ref BufferSpan, short), WriteMinecraftBufferExtensions.WriteString<BufferSpan>(ref BufferSpan, ReadOnlySpan<char>), WriteMinecraftBufferExtensions.WriteTag<BufferSpan>(ref BufferSpan, NbtTag, bool), WriteMinecraftBufferExtensions.WriteUnsignedByte<BufferSpan>(ref BufferSpan, byte), WriteMinecraftBufferExtensions.WriteUnsignedShort<BufferSpan>(ref BufferSpan, ushort), WriteMinecraftBufferExtensions.WriteUuid<BufferSpan>(ref BufferSpan, Uuid), WriteMinecraftBufferExtensions.WriteUuidAsIntArray<BufferSpan>(ref BufferSpan, Uuid), WriteMinecraftBufferExtensions.WriteVarInt<BufferSpan>(ref BufferSpan, int), WriteMinecraftBufferExtensions.WriteVarIntArray<BufferSpan>(ref BufferSpan, scoped ReadOnlySpan<int>), WriteMinecraftBufferExtensions.WriteVarLong<BufferSpan>(ref BufferSpan, long), WriteMinecraftBufferExtensions.WriteVarShort<BufferSpan>(ref BufferSpan, int)

Constructors

BufferSpan(Span<byte>)

Initializes a new instance of the BufferSpan class with a byte span.

public BufferSpan(Span<byte> source)

Parameters

source Span<byte>

The byte span provides the data to be managed within the BufferSpan instance.

Properties

Length

Returns the length of the source as an integer. It is a read-only property.

public readonly int Length { get; }

Property Value

int

Position

Gets or sets the position within a buffer. The position must be between 0 and the length of the source, otherwise an exception is thrown.

public int Position { readonly get; set; }

Property Value

int

Remaining

Calculates the number of remaining elements in a source collection. It subtracts the current position from the total length.

public readonly int Remaining { get; }

Property Value

int

Methods

Access(int)

Retrieves a span of bytes from the underlying buffer starting at the current position for the specified length. This method does not modify the current position of the buffer.

public readonly Span<byte> Access(int length)

Parameters

length int

The number of bytes to retrieve from the current position. Must be non-negative.

Returns

Span<byte>

A representing the specified number of bytes from the current position.

Access(int, int)

Retrieves a span of bytes from the underlying buffer starting at the specified position for the given length.

public readonly Span<byte> Access(int position, int length)

Parameters

position int

The starting position in the buffer from which to retrieve the byte span. Must be a non-negative value.

length int

The number of bytes to include in the retrieved span. Must be non-negative.

Returns

Span<byte>

A containing the specified range of bytes.

Dispose()

Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.

public readonly void Dispose()

Seek(int, SeekOrigin)

Advances or sets the current position in the buffer relative to the specified origin.

public void Seek(int offset, SeekOrigin origin = SeekOrigin.Current)

Parameters

offset int

The byte offset relative to the origin.

origin SeekOrigin

The point of reference used to obtain the new position.

Slice(int, int)

Extracts a portion of a buffer starting from a specified position for a given length.

public readonly BufferSpan Slice(int position, int length)

Parameters

position int

Indicates the starting point from which the extraction begins.

length int

Specifies the number of elements to include in the extracted portion.

Returns

BufferSpan

Returns a new buffer containing the specified slice of the original buffer.