Table of Contents

Interface ICStructGenerated<TSelf>

Namespace
CStructSharp
Assembly
CStructSharp.dll

Implemented by the root class the [CStructLayout] generator emits, so generic code can accept any generated root: the runtime CStruct for the same layout, the root name, and the generated span operations.

public interface ICStructGenerated<TSelf> where TSelf : ICStructGenerated<TSelf>

Type Parameters

TSelf

The generated root class.

Properties

Layout

Gets the runtime layout the class was generated from (built lazily on first use).

public static abstract CStruct Layout { get; }

Property Value

CStruct

RootName

Gets the declaration name the class corresponds to.

public static abstract string RootName { get; }

Property Value

string

Methods

Parse(ReadOnlySpan<byte>, ReadOptions?)

Parses one value from source with the generated reader.

public static abstract TSelf Parse(ReadOnlySpan<byte> source, ReadOptions? options = null)

Parameters

source ReadOnlySpan<byte>

The bytes; offset 0 is coordinate zero.

options ReadOptions

The read options; null uses the documented defaults.

Returns

TSelf

The parsed value.

Serialize(TSelf, Span<byte>, WriteOptions?)

Serializes value into destination with the generated writer.

public static abstract int Serialize(TSelf value, Span<byte> destination, WriteOptions? options = null)

Parameters

value TSelf

The value to encode.

destination Span<byte>

The bytes to write into.

options WriteOptions

The write options; null uses the documented defaults.

Returns

int

The number of bytes written.

TryParse(ReadOnlySpan<byte>, out TSelf, out CStructException?, ReadOptions?)

Parses one value without throwing for a read, path, or limit failure: false and the failure the throwing form would have raised. Cancellation and argument errors throw as in Parse(ReadOnlySpan<byte>, ReadOptions?).

public static abstract bool TryParse(ReadOnlySpan<byte> source, out TSelf value, out CStructException? failure, ReadOptions? options = null)

Parameters

source ReadOnlySpan<byte>

The bytes; offset 0 is coordinate zero.

value TSelf

The parsed value, or null when the read failed.

failure CStructException

The failure, or null.

options ReadOptions

The read options; null uses the documented defaults.

Returns

bool

Whether the read succeeded.