TPLWorkflowReadSlice

Native Pascal, workflow preparation

Description

TPLWorkflowReadSlice is a nonowning, read-only TStream window over an absolute range of a seekable source. Its position is relative to the slice, while the offset and count given to the constructor are absolute in the source, so a region can be exposed to a parser without copying it.

The workflow console example wraps its staged request stream in a full-range slice before copying it through PLCopyWorkflowStream; see WorkflowDataTools for the surrounding copy and budget rules.

Syntax

Delphi

TPLWorkflowReadSlice = Class(TStream)
  Public
    Constructor Create(Source: TStream; Offset, Count: Int64;
      PreserveSourcePosition: Boolean= True);
    Function Read(Var Buffer; Count: Longint): Longint; Override;
    Function Write(Const Buffer; Count: Longint): Longint; Override;
    Function Seek(Const Offset: Int64; Origin: TSeekOrigin): Int64; Override;
  End;

Fields

Create(Source, Offset, Count, PreserveSourcePosition)Validates the range against the current source size and stores the source reference; it reads no bytes and raises EStreamError for a Nil source, a negative offset or count, or a range beyond the source
ReadCopies up to Count bytes from the current position, never past the slice end; with position preservation enabled the source position is restored afterwards
WriteAlways raises EStreamError, because a slice is read-only
SeekAccepts soBeginning, soCurrent and soEnd offsets within the slice; a position outside 0 through Count raises EStreamError

Remarks

The source must be seekable, must remain alive and must not change while the slice is used; the slice never frees or modifies it.

PreserveSourcePosition defaults to True; when it is False each read leaves the source at the end of the bytes it returned, so concurrent users of the source will interfere.

The inherited Size property reports Count, because the size getter seeks to soEnd.

Reads request a bounded span and raise EReadError if the source reports an impossible byte count.

See also

WorkflowDataTools, TWorkflowCheckpoint