Show / Hide Table of Contents

Method FastBuffer<T>.TryRead(+ 4 overloads)


Overload

Gets a read-only span whose memory is in the buffer at FastBuffer<T>.Position. No copying.

public bool TryRead<TElem>(int nElem, out ReadOnlySpan<TElem> data) where TElem : unmanaged
Parameters
nElem  (int)

Number of elements of type TElem in the returned span.

data  (ReadOnlySpan<TElem>)

Read-only span to return.

Returns
bool

false if there is not enough memory in the buffer at FastBuffer<T>.Position for the the requested data size.

Exceptions
InvalidOperationException

The generic type of this is not byte.

Type Parameters
TElem

Remarks

The generic type of this must be byte.

If successful, finally sets FastBuffer<T>.Position = the end of the requested data.


Overload(next)

Gets a read-only span whose memory is in the buffer at FastBuffer<T>.Position. No copying. At first reads its length as int.

public bool TryRead<TElem>(out ReadOnlySpan<TElem> data) where TElem : unmanaged
Parameters
data  (ReadOnlySpan<TElem>)

Read-only span to return.

Returns
bool

false if there is not enough memory in the buffer at FastBuffer<T>.Position for the the requested data size.

Exceptions
InvalidOperationException

The generic type of this is not byte.

Type Parameters
TElem

Remarks

The generic type of this must be byte.

If successful, finally sets FastBuffer<T>.Position = the end of the requested data.


Overload(next)

Reads a struct from the buffer at FastBuffer<T>.Position.

public bool TryRead<TData>(out TData data) where TData : unmanaged
Parameters
data  (TData)
Returns
bool

false if there is not enough memory in the buffer at FastBuffer<T>.Position for the the requested data size.

Exceptions
InvalidOperationException

The generic type of this is not byte.

Type Parameters
TData

Remarks

The generic type of this must be byte.

If successful, finally sets FastBuffer<T>.Position = the end of the requested data.


Overload(next)

Reads a string of specified length from the buffer at FastBuffer<T>.Position.

public bool TryRead(int nChars, out string data)
Parameters
nChars  (int)

Requested string length.

data  (string)
Returns
bool

false if there is not enough memory in the buffer at FastBuffer<T>.Position for the the requested data size.

Exceptions
InvalidOperationException

The generic type of this is not byte.

Remarks

The generic type of this must be byte.

If successful, finally sets FastBuffer<T>.Position = the end of the requested data.


Overload(top)

Reads a string from the buffer at FastBuffer<T>.Position. At first reads its length as int.

public bool TryRead(out string data)
Parameters
data  (string)
Returns
bool

false if there is not enough memory in the buffer at FastBuffer<T>.Position for the the requested data size.

Exceptions
InvalidOperationException

The generic type of this is not byte.

Remarks

The generic type of this must be byte.

If successful, finally sets FastBuffer<T>.Position = the end of the requested data.