ModelStateEnvelope
Helpers & Utilities · AiDotNet.Models
Attaches declared state to a payload whose format this code does not know.
How It Works
There are twenty-six parallel model base hierarchies, each with its own byte[] Serialize()
and its own format – some JSON, some binary, some nested metadata. They are siblings over the
same interfaces rather than a hierarchy, so there is no one place to put a state block and no
single format to put it in.
So the state is appended as a SUFFIX and located from the END: the trailer is the magic and the block length, which means the existing payload in front of it is untouched and does not need to be understood. A payload written before this existed simply has no trailer, so it reads back exactly as it always did – old checkpoints keep working instead of failing on a format they could not have known about.
Methods
| Method | Summary |
|---|---|
byte[] Append(ModelStateRegistry<T> state, byte[] payload) |
Appends the declared state to a payload, or returns it unchanged when none exists. |
byte[] Extract(ModelStateRegistry<T> state, byte[] payload) |
|
byte[] ExtractAfterParameters(ModelStateRegistry<T> state, byte[] payload) |
Applies only exact native-precision parameter shadows from an envelope. |
byte[] ExtractBeforeParameters(ModelStateRegistry<T> state, byte[] payload) |
Applies structural state and strips the envelope, deferring exact native-precision parameter shadows until the ordinary flat parameter vector has been restored. |