Serializer

Description

A reflection-driven binary serializer. It walks an object’s fields and writes / reads them recursively through a BinaryWriter / BinaryReader. Two modes: All (every field) and Attributed (only [@Serializable] fields, skipping [NonSerializable]). Used for the font atlas data (.agd) and scenes.

API summary

MemberKindSummary
SerializeAttributed<T>(T obj, string path)staticWrite only [@Serializable] fields.
DeserializeAttributed<T>(string path, ref T obj)staticRead them back.
SerializeAll<T>(T obj, string path)staticWrite every field (ignores attributes). Use at your own risk.
DeserializeAll<T>(string path, ref T obj)staticNOT IMPLEMENTEDRecursiveDeserializeAll is a stub.

Fields & Properties

private static readonly HashSet<Type> _builtInTypes = { string, decimal, DateTime, DateTimeOffset, TimeSpan, Guid, char, int, float };
// IsBuiltInType also covers all primitives, enums, and Nullable<T> of the above.

Methods

Serialize

RecursiveSerialize{All,Attributed} walk the fields: skip [NonSerializable] primitive → ConvertToBytes → write string → length + UTF-8 bytes struct → recurse array → length, then each element In Attributed mode, array/complex elements must themselves be [@Serializable] and are written with a hashed type ID (Serializable.GenerateID) before the element body.

Deserialize

RecursiveDeserializeAttributed mirrors it: primitive via ConvertToBytes(Type) + BitConverter string via length struct/class via Activator.CreateInstance + recurse array elements are resolved by reading the hashed type ID and looking it up in the IDMap registry (Asset Registries) DeserializeAll is currently a TODO stub.

Helpers

private static byte[] ConvertToBytes(object value);  // primitive → bytes
private static byte[] ConvertToBytes(Type type);     // zeroed buffer sized to the primitive (for reads)
private static byte[] ReturnDefault(Type type);      // default bytes for a null serializable