Class Bytes
- Namespace
- MarymoorStudios.Core.Rpc
- Assembly
- MarymoorStudios.Core.Rpc.dll
public sealed class Bytes : IPromiseDisposable, IDisposable
- Inheritance
-
Bytes
- Implements
- Inherited Members
Properties
BatchSize
The batch size suggested by the reader.
public int BatchSize { get; set; }
Property Value
Capacity
The desired capacity of the reader.
public int Capacity { get; set; }
Property Value
Methods
Cancel(Exception?)
Attempts to perform a graceful early termination by the sequence with a diagnostic error for the Writer.
public void Cancel(Exception? error = null)
Parameters
error
ExceptionAn optional diagnostic error. If no error is provided then OperationCanceledException will be sent.
Remarks
The Read() method will eventually return EOS (or error) after Cancel(Exception?) has been called, either because cancellation is successfully propagated to the Writer or because the underlying channel is aborted before cancellation can be propagated.
Cancellation is pr
Create(Func<Writer, Promise>, int, int)
Constructs a new Pipe<T>
public static Bytes Create(Func<Bytes.Writer, Promise> body, int capacity = 65536, int batchSize = 8192)
Parameters
body
Func<Bytes.Writer, Promise>A function that will generate the contents of the sequence.
capacity
intThe maximum number of items before backpressure is applied.
batchSize
intThe reader suggested batch size.
Returns
Remarks
REQUIRES: capacity
> 0
REQUIRES: 1 <= batchSize
<= capacity
The batchSize is used to decrease ping-ponging by delaying waking the producer until there are more items in the window. There is a tradeoff between added latency and buffering costs on the writer side versus signalling costs. The default value is 1 causing the producer to be signalled whenever there is at least one slot available.
Create(int, int)
Constructs a new Pipe<T>
public static (Bytes reader, Bytes.Writer writer) Create(int capacity = 65536, int batchSize = 8192)
Parameters
capacity
intThe maximum number of items before backpressure is applied.
batchSize
intThe reader suggested batch size.
Returns
Remarks
REQUIRES: capacity
> 0
REQUIRES: 1 <= batchSize
<= capacity
The batchSize is used to decrease ping-ponging by delaying waking the producer until there are more items in the window. There is a tradeoff between added latency and buffering costs on the writer side versus signalling costs. The default value is 1 causing the producer to be signalled whenever there is at least one slot available.
Dispose()
Releases all received but unread items.
public void Dispose()
Remarks
Implies a call to Cancel(Exception?) if the sequence has not seen EOS or already been cancelled.
Any items that are received by the transport after the Reader has been disposed will be immediately released.
DisposeAsync()
Releases all received but unread items.
public Promise DisposeAsync()
Returns
- Promise
A promise that resolves when all in-flight items have been exhausted from the transport.
Remarks
Implies a call to Cancel(Exception?) if the sequence has not seen EOS or already been cancelled.
Any items that are received by the transport after the Reader has been disposed will be immediately released.
ForEach(Func<OwnedMem<byte>, Promise>)
Yields each of the items in the sequence to the body
function.
public Promise ForEach(Func<OwnedMem<byte>, Promise> body)
Parameters
Returns
- Promise
Resolves successfully if the entire sequence was read to the end without encountering an error, otherwise breaks with the first error encountered by the sequence.
Read()
Reads the next available item from the sequence.
public Promise<OwnedMem<byte>> Read()
Returns
Remarks
Returns the next item in the sequence. If there are no items available immediately, then the return resolves when the next item arrives.
On a successful return ownership for the item returned is transferred to the caller who is responsible for disposing it.
If the end of the sequence (EOS) is reached (i.e. a finite sequence) then reading after the EOS will yield an EndOfSequenceException error.
If the sequence is closed by the Writer with an error, that error will be returned in sequence order after all items successfully written before the error have been delivered.
If the sequence is aborted by the Writer or the underlying transport a read will yield an AbortedException. Some items in the sequence may have been lost in the event of an abort.