Namespace CStructSharp
Classes
- CStruct
Compiles a C-like layout definition and uses it to read, inspect, write, or update binary data. Create one instance per layout, then reuse it for sequential or concurrent operations. Concurrent calls must use distinct streams, payload graphs, and other mutable resources, or the caller must synchronize each shared resource for the complete operation.
- CStructCompilationOptions
Controls the resource limits applied before a C-like layout definition is parsed and compiled.
- CStructLayoutAttribute
Asks the CStructSharp source generator to turn a layout into C# at compile time: one class per struct and union, an enum per layout enum, and straight-line
Parse,Serialize,Update, andResolveAddressmethods on the attributedstatic partialclass, with the same results and the same diagnostics as CStruct produces for the same definition and options.
- CStructMappedAttribute
Asks the CStructSharp source generator to implement ICStructMapped<TSelf> for a
partialclass:ReadFromandWriteToassign the class's public members by name, with the conversions Get<T>(string) applies, and a module initializer registers the type with MappedTypes.
- CStructMemberAttribute
Names the layout member a property or field of a
[CStructMapped]class maps to, when the C# name differs.
- FieldAccessor<T>
One member path of a layout, resolved once and read many times:
layout.GetAccessor<float>("reading.pos.x"). Reading a member by a path string parses the path and looks up every segment on each call; an accessor does that work when it is created, so a read is a few array lookups (Get(StructValue)) or a decode at a constant byte offset (Read(ReadOnlySpan<byte>, ReadOptions?), Get<T>(FieldAccessor<T>)).
- MappedTypes
The registry of classes that implement ICStructMapped<TSelf>. Registration captures the type's static mapping members as delegates once, under the generic constraint, so the read and write paths can map an instance from its Type alone - no reflection, and therefore no trimming or Native AOT conventions. Generated mappers register themselves in a module initializer; a hand-written mapper does the same, or calls Register<T>() once at startup (registering twice is harmless).
- MatchRule
One recognition rule and whether a prepared matcher checks it.
- PreparedMatcher
Immutable runtime recognition decisions, reusable with independent execution state on any thread.
- ReadOptions
Controls the safety budgets and pointer policy shared by parsing, debug parsing, selected reads, address resolution, and dynamic-length lookup.
- StaticHelpers
Contains small conversion helpers shared by examples, tests, and callers.
- UpdateOptions
Adds bounded read-side traversal and in-place replacement choices to the normal write options. Updates validate against sparse staging before commit and cannot extend the existing destination stream.
- WriteOptions
Controls serialization and stream-writing operations performed by CStruct.
Structs
- ReadLimits
The limits of one read as a value: the same bounds as the matching ReadOptions members, without an object to allocate. A reader that parses many small records builds one ReadLimits (or none, for the defaults) instead of a ReadOptions per call.
- StructView
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")orview.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.
Interfaces
- ICStructFixedMapped<TSelf>
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>andSerializeof a whole struct from memory use them instead of building a StructValue when the layout of the call has the same FixedLayoutFingerprint.
- ICStructGenerated<TSelf>
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.
- ICStructMapped<TSelf>
A class that maps to and from a layout composite without reflection: ReadFrom(StructValue) builds an instance from a parsed StructValue and WriteTo(TSelf, StructValue) fills a StructValue of the layout's shape from an instance. The
[CStructMapped]source generator writes both members for apartialclass; a class may also implement them by hand. Register<T>() makes the type known to ReadValue<T>(Stream, string?, IReadOnlyDictionary<string, int>?, ReadOptions?), Get<T>(string), and the write operations. Register from a module initializer ([ModuleInitializer] internal static void Register() => MappedTypes.Register<Point>();), as generated code does: a module initializer runs before any other code in the assembly on every runtime, Native AOT included, whereas a static constructor that nothing else triggers is removed by the AOT compiler.
Enums
- BitfieldAllocation
Which end of a storage unit the first bitfield takes.
- BitfieldPacking
Selects which C compiler family's rule places adjacent bitfields of different declared types.
- ConstraintFailureMode
Chooses the exception type a generated reader throws for a field that breaks an
@expector@supportsconstraint. It is the ConstraintFailures option (project default: the build propertyCStructSharpConstraintFailures).
- ConstraintPolicy
Chooses whether a read evaluates the
@expectand@supportsconstraints of its layout. It is the Constraints and Constraints setting of one read.
- GeneratedShape
Chooses the C# type the generator makes of each struct and union of a layout.
- GeneratedSurface
Chooses how much code CStructLayoutAttribute generates for a layout. A smaller surface compiles faster and adds less to the assembly; every surface reads the same bytes with the same results and failures.
- InvalidTextHandling
Chooses what a read does with text that is not valid in its encoding.
- PointerAddressingMode
Lists how pointer addresses in the input stream should be interpreted.
- UnknownMemberPolicy
Says what a write does with a supplied member that the layout does not declare.