Table of Contents

Interface ICStructFixedMapped<TSelf>

Namespace
CStructSharp
Assembly
CStructSharp.dll

The direct read and write of a mapped class bound to one fixed-layout struct, which the source generator emits for a [CStructMapped(Layout = "...")] class whose layout struct has a build-time offset for every member. ReadValue<T> and Serialize of a whole struct from memory use them instead of building a StructValue when the layout of the call has the same FixedLayoutFingerprint.

public interface ICStructFixedMapped<TSelf> where TSelf : ICStructFixedMapped<TSelf>

Type Parameters

TSelf

The mapped class.

Remarks

An implementation promises the results of the class's ICStructMapped<TSelf> members over a struct of that layout: the same property values from the same bytes, and the same bytes from the same instance. It returns false for anything it does not handle exactly that way, and the caller then takes the ICStructMapped<TSelf> route. Hand-written implementations take on that promise; the generated ones are held to it by the repository's parity tests.

Properties

FixedLayoutFingerprint

Gets the fingerprint of the layout struct the direct members were generated for.

public static abstract ulong FixedLayoutFingerprint { get; }

Property Value

ulong

Methods

TryReadFixed(ReadOnlySpan<byte>, bool, out TSelf)

Reads an instance from the struct's bytes, each property from its member's constant offset.

public static abstract bool TryReadFixed(ReadOnlySpan<byte> source, bool trimFixedText, out TSelf value)

Parameters

source ReadOnlySpan<byte>

The struct's bytes, at least its size.

trimFixedText bool

Whether fixed-capacity text drops its trailing NUL padding (TrimFixedText).

value TSelf

The instance when the method returns true.

Returns

bool

false when a property cannot be read directly; nothing has been observed then.

TryWriteFixed(TSelf, Span<byte>)

Writes an instance into the struct's bytes, each property at its member's constant offset.

public static abstract bool TryWriteFixed(TSelf value, Span<byte> target)

Parameters

value TSelf

The instance.

target Span<byte>

The struct's bytes, already zero (so padding is written as zeros), at least its size.

Returns

bool

false when the instance cannot be written directly; the caller then discards target.