Table of Contents

Class MemoryFieldReader<T>

Namespace
CStructSharp.Memory
Assembly
CStructSharp.dll

A typed scalar reader whose schema decisions are prepared once and whose operation state is supplied on each read.

public sealed class MemoryFieldReader<T>

Type Parameters

T

Exact managed scalar result type, or StoredPointer for stored pointer bits.

Inheritance
MemoryFieldReader<T>
Inherited Members

Properties

Selection

Gets the schema-only selection, including offset and field metadata.

public MemoryPath Selection { get; }

Property Value

MemoryPath

Methods

Read(MemorySession, MemoryRegion, MemoryAccessContext?)

Reads one value using fresh pointer resolution and the supplied operation budget.

public T Read(MemorySession session, MemoryRegion region, MemoryAccessContext? context = null)

Parameters

session MemorySession

Session owning the identical schema instance.

region MemoryRegion

Finite root record storage.

context MemoryAccessContext

Shared operation context, or null to create one.

Returns

T

The selected value without numeric scalar boxing.

Exceptions

CStructException

Selection, source, or budget failure.

ArgumentException

The session owns a different schema.

OperationCanceledException

Cancellation was requested.

TryRead(MemorySession, MemoryRegion, out T, out MemoryReadFailure?, MemoryAccessContext?)

Reads one value, returning expected missing memory and pointer failures without throwing internally.

public bool TryRead(MemorySession session, MemoryRegion region, out T value, out MemoryReadFailure? failure, MemoryAccessContext? context = null)

Parameters

session MemorySession

Session owning the identical schema.

region MemoryRegion

Caller-owned root storage.

value T

Decoded value on success; default on false.

failure MemoryReadFailure

Structured failure on false, null on success.

context MemoryAccessContext

Shared operation budget; null creates one.

Returns

bool

Whether selection and decoding succeeded.

Remarks

Source implementations and custom codecs may themselves throw. Cancellation and exhausted budgets always propagate. No context or captured bytes are retained.

Exceptions

MemoryAccessException

An operation budget was exhausted.

OperationCanceledException

Cancellation was requested.

TryReadBuffer(ReadOnlySpan<byte>, MemoryAccessContext, out T, MemoryValidity?)

Decodes only this fixed field from a caller-owned captured buffer, without requiring unrelated root bytes.

public bool TryReadBuffer(ReadOnlySpan<byte> source, MemoryAccessContext context, out T value, MemoryValidity? validity = null)

Parameters

source ReadOnlySpan<byte>

Bytes beginning at the root's logical start.

context MemoryAccessContext

Shared local decoding budget and cancellation; one request and the field's bytes are charged even for unavailable input.

value T

Exact decoded result on success; default when required bytes are absent.

validity MemoryValidity

Known-byte intervals for this exact buffer length, or null when every supplied byte is known.

Returns

bool

Whether all selected storage bytes were present and known.

Remarks

This explicit buffer operation does not weaken region reads. Pointer-following paths are unsupported. Unknown bytes never decode as zero. Custom codecs retain their normal decode behavior; exceptions propagate. Caller guarantees buffer stability and lifetime.

Exceptions

NotSupportedException

The path follows a pointer.

ArgumentException

Validity describes another buffer length.

MemoryAccessException

The operation budget is exhausted.

OperationCanceledException

Cancellation was requested.