Table of Contents

Class VersatileBufferStream

Namespace
VAST.Common
Assembly
VAST.Common.dll

Provides a stream abstraction over one or more VersatileBuffer instances.

public class VersatileBufferStream : BitStream, IDisposable, IAsyncDisposable
Inheritance
VersatileBufferStream
Implements
Inherited Members

Remarks

This class allows reading and writing data across multiple underlying buffers as if they were a single contiguous stream. It supports bit-level operations through the BitStream base class.

Constructors

VersatileBufferStream()

Creates instance of an empty stream

public VersatileBufferStream()

VersatileBufferStream(VersatileBuffer)

Creates the stream using the specified packet buffer

public VersatileBufferStream(VersatileBuffer packet)

Parameters

packet VersatileBuffer

Packet buffer containing the real data

VersatileBufferStream(VersatileBuffer, int, int)

Creates the stream using the specified packet buffer, offset and count bytes

public VersatileBufferStream(VersatileBuffer packet, int offset, int count)

Parameters

packet VersatileBuffer

Packet buffer containing the real data

offset int

Offset of the data in the buffer

count int

Number of bytes to use

Properties

AutoGrowth

Gets or sets a value indicating whether the stream automatically grows when data being written exceeds the remaining space.

public bool AutoGrowth { get; set; }

Property Value

bool

BitPosition

Gets or sets the current bit position within the current byte (0-7).

public override int BitPosition { get; set; }

Property Value

int

Exceptions

ArgumentOutOfRangeException

Thrown when the value is less than 0 or greater than or equal to 8.

CanRead

Gets a value indicating whether the stream supports reading. Always returns true.

public override bool CanRead { get; }

Property Value

bool

CanSeek

Gets a value indicating whether the stream supports seeking. Always returns true.

public override bool CanSeek { get; }

Property Value

bool

CanWrite

Gets a value indicating whether the stream supports writing. Always returns true.

public override bool CanWrite { get; }

Property Value

bool

Length

Gets the total length of the stream in bytes.

public override long Length { get; }

Property Value

long

Position

Gets or sets stream position

public override long Position { get; set; }

Property Value

long

Methods

Append(VersatileBuffer, int, int)

Append specified packet buffer to current stream. This function doesn't do any actual memory copy. Instead it just adds new buffer to the underlying buffer list.

public void Append(VersatileBuffer buffer, int offset, int count)

Parameters

buffer VersatileBuffer

Packet buffer to append

offset int

Offset in the packet buffer

count int

Number of bytes to use from the packet buffer

CopyTo(Stream, int)

Copies the specified number of bytes from the current position to the target stream.

public int CopyTo(Stream stream, int count)

Parameters

stream Stream

The target stream to copy data to.

count int

The number of bytes to copy.

Returns

int

The number of bytes actually copied.

CopyTo(Stream, long, int, bool)

Copies specified number of bytes from current position to specified stream.

public int CopyTo(Stream stream, long fromPosition, int count, bool setFinalPosition)

Parameters

stream Stream

Target stream receiving the data

fromPosition long

Start copying from

count int

Number of bytes to copy

setFinalPosition bool

Whether stream position should be set to a final position after the reading finished

Returns

int

Number of bytes actually copied

Flush()

Flush the stream (not applicable for current class)

public override void Flush()

MoveTo(VersatileBufferStream)

Copies data from the beginning of the stream till current position to the output stream and then resets current stream position to 0, all under the lock. Necessary to serve as endless input buffer, eg for endless HTTP request.

public int MoveTo(VersatileBufferStream stream)

Parameters

stream VersatileBufferStream

Target stream receiving the data

Returns

int

Number of bytes actually copied

PeekByte()

Peek one byte from the stream

public override int PeekByte()

Returns

int

Byte read at current stream position

Read(byte[], int, int)

Read specified number of bytes to a byte buffer

public override int Read(byte[] buffer, int offset, int count)

Parameters

buffer byte[]

Byte buffer to hold read data

offset int

Offset of the read buffer

count int

Number of bytes to read

Returns

int

Number of bytes actually read

Read(Span<byte>)

Read from current position to a specified buffer

public override int Read(Span<byte> buffer)

Parameters

buffer Span<byte>

Buffer to hold read data

Returns

int

Number of bytes actually read

ReadByte()

Read one byte from the stream

public override int ReadByte()

Returns

int

Byte read at current stream position

ReadFrom(long, byte[], int, int)

Reads data from the specified position into a byte array without changing the current stream position.

public int ReadFrom(long fromPosition, byte[] buffer, int offset, int count)

Parameters

fromPosition long

The position in the stream to read from.

buffer byte[]

The byte array to store the read data.

offset int

The offset in the buffer to start writing data.

count int

The number of bytes to read.

Returns

int

The number of bytes actually read.

Exceptions

ArgumentNullException

Thrown when buffer is null.

Seek(long, SeekOrigin)

Seek to a specified position

public override long Seek(long offset, SeekOrigin origin)

Parameters

offset long

Target offset

origin SeekOrigin

Target origin

Returns

long

Position after applying the specified offset

SeekBits(long, SeekOrigin)

Seeks to a specified bit position within the stream.

public override long SeekBits(long offset, SeekOrigin origin)

Parameters

offset long

The bit offset relative to the origin.

origin SeekOrigin

The reference point for the offset.

Returns

long

The new byte position after seeking.

Exceptions

ArgumentOutOfRangeException

Thrown when the resulting position is outside the stream bounds.

SetLength(long)

Sets the length of the stream by truncating data beyond the specified value.

public override void SetLength(long value)

Parameters

value long

The new length of the stream. Must be less than or equal to the current length.

Exceptions

ArgumentOutOfRangeException

Thrown when value is greater than the current length.

SliceTo(VersatileBufferStream)

Copies all data from current stream to specified stream without actual memory copy, only by referencing the buffers.

public int SliceTo(VersatileBufferStream stream)

Parameters

stream VersatileBufferStream

Target stream receiving the data

Returns

int

Number of bytes actually copied

SliceTo(VersatileBufferStream, long, int)

Copies data range from current stream to specified stream without actual memory copy, only by referencing the buffers.

public int SliceTo(VersatileBufferStream stream, long fromPosition, int count)

Parameters

stream VersatileBufferStream

Target stream receiving the data

fromPosition long

Start copying from

count int

Number of bytes to copy

Returns

int

Number of bytes actually copied

TrimBegin()

Drops all data from the beginning of the stream up to the current position.

public void TrimBegin()

TrimBegin(long)

Drop all data from the beginning of the stream till current position

public void TrimBegin(long trimPosition)

Parameters

trimPosition long

UnlockedCopyTo(Stream, long, int)

Copies specified number of bytes from current position to specified output stream. Operation doesn't affect any local variables or properties and must be performed on finalized stream which will not be changed for sure during this operation.

public int UnlockedCopyTo(Stream stream, long fromPosition, int count)

Parameters

stream Stream

Target stream receiving the data

fromPosition long

Position to copy from

count int

Number of bytes to copy

Returns

int

Number of bytes actually copied

Write(byte[], int, int)

Write specified number of bytes from the byte buffer to the stream

public override void Write(byte[] buffer, int offset, int count)

Parameters

buffer byte[]

Byte buffer to write data from

offset int

Byte buffer offset

count int

Number of bytes to write