Struct StructView
- Namespace
- CStructSharp
- Assembly
- CStructSharp.dll
The bytes of one struct, read member by member when asked instead of all at once: the runtime counterpart of a
generated view. layout.CreateView(bytes, "reading") builds nothing; view.Get<float>("pos.x")
or view.Get(accessor) reads one member. In a struct whose members all have build-time offsets, a
fixed-width number read as its own type is decoded straight from the span and nothing is allocated.
public readonly ref struct StructView
- Inherited Members
Remarks
Every member read returns what layout.ReadValue<T>(bytes, root + "." + path, options: options)
returns, and fails as it fails; members the view cannot decode directly (text, enums, whole arrays, nested structs
as values, converted types, runtime-sized layouts) are read exactly that way. A view is a ref
struct over the caller's memory: it cannot be stored in a field or used after the memory changes.
Properties
Bytes
Gets the struct's bytes: exactly its size for a fixed-size struct, otherwise the whole source.
public ReadOnlySpan<byte> Bytes { get; }
Property Value
Root
Gets the struct declaration the view reads.
public string Root { get; }
Property Value
Methods
Get<T>(FieldAccessor<T>)
Reads one member through a prepared accessor for this view's layout and root.
public T Get<T>(FieldAccessor<T> accessor)
Parameters
accessorFieldAccessor<T>An accessor from
GetAccessor<T>of the same layout, for a path starting at Root.
Returns
- T
The member.
Type Parameters
TThe type the member is read as.
Exceptions
- ArgumentException
The accessor belongs to another layout or root.
- CStructPathException
The path cannot be resolved.
- CStructReadException
The bytes cannot be decoded or converted to
T.
Get<T>(string)
Reads one member by its path below the root (pos.x, samples[3]); the path is resolved once per layout and type.
public T Get<T>(string path)
Parameters
Returns
- T
The member.
Type Parameters
TThe type the member is read as.
Exceptions
- CStructPathException
The path is malformed or cannot be resolved.
- CStructReadException
The bytes cannot be decoded or converted to
T.
ToStructValue()
Parses the whole struct into a StructValue, as layout.Parse(bytes, root, options: options) does.
public StructValue ToStructValue()
Returns
- StructValue
The parsed struct.