Table of Contents

Class PacketBuffer

Namespace
Xabbo.Messages
Assembly
Xabbo.Common.dll

Represents a resizable buffer backed by a rented memory span of byte from a MemoryPool<T> .

public sealed class PacketBuffer : IDisposable
Inheritance
PacketBuffer
Implements

Constructors

PacketBuffer(in ReadOnlySequence<byte>)

Constructs a new buffer and copies the specified ReadOnlySequence<T> into its internal memory.

public PacketBuffer(in ReadOnlySequence<byte> data)

Parameters

data ReadOnlySequence<byte>

The data to copy into this buffer.

PacketBuffer(int)

Represents a resizable buffer backed by a rented memory span of byte from a MemoryPool<T> .

public PacketBuffer(int minimumCapacity = 32)

Parameters

minimumCapacity int

The initial minimum capacity of the rented span of bytes.

PacketBuffer(ReadOnlySpan<byte>)

Constructs a new buffer and copies the specified ReadOnlySpan<T> into its internal memory.

public PacketBuffer(ReadOnlySpan<byte> data)

Parameters

data ReadOnlySpan<byte>

The data to copy into this buffer.

Properties

Length

Gets the length of the buffer.

public int Length { get; }

Property Value

int

Span

Gets the memory of the buffer as a Span<T>.

public Span<byte> Span { get; }

Property Value

Span<byte>

Methods

Allocate(int, int)

Allocates length bytes from the start position and returns the allocated range as a Span<T> of bytes.

If start+length is greater than the buffer length, the buffer is grown to support the new length.

start may not be greater than the current length.
public Span<byte> Allocate(int start, int length)

Parameters

start int
length int

Returns

Span<byte>

Clear()

Resets the buffer's length to zero.

public void Clear()

Copy()

Creates a new copy of this buffer.

public PacketBuffer Copy()

Returns

PacketBuffer

Dispose()

Disposes of this buffer and releases its memory back to the memory pool.

public void Dispose()

Grow(int)

Grows the buffer to the specified length if the current length is insufficient.

public void Grow(int min)

Parameters

min int

Resize(Range, int)

Resizes the specified range of the buffer to the specified length and returns the resized range as a Span<T> of bytes.

The tail portion of the buffer after the end of the range will be copied into the correct position.

If the range grows in length, the expanded portion of the range is not cleared, so it is the caller's responsibility to write valid data to the resulting span.
public Span<byte> Resize(Range range, int length)

Parameters

range Range
length int

Returns

Span<byte>