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
TExact 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
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
sessionMemorySessionSession owning the identical schema instance.
regionMemoryRegionFinite root record storage.
contextMemoryAccessContextShared 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
sessionMemorySessionSession owning the identical schema.
regionMemoryRegionCaller-owned root storage.
valueTDecoded value on success; default on false.
failureMemoryReadFailureStructured failure on false, null on success.
contextMemoryAccessContextShared 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
sourceReadOnlySpan<byte>Bytes beginning at the root's logical start.
contextMemoryAccessContextShared local decoding budget and cancellation; one request and the field's bytes are charged even for unavailable input.
valueTExact decoded result on success; default when required bytes are absent.
validityMemoryValidityKnown-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.