Class ComponentPayload
- Namespace
- GrindFest
- Assembly
- GrindFest.dll
The payload of a saveable component (ISerializableComponent). Opaque bytes on purpose: a component - ours or a mod's - may use any encoding it likes (this helper uses MemoryPack) instead of being tied to a JSON string.
Layout: one version byte, then the body. There is deliberately no magic and no legacy format - a payload is written and read by the component that owns it and by nobody else, so there is nothing to disambiguate. A payload that does not read back (an unknown version, corrupt bytes, or the JSON text left in a save from before the binary format) simply makes TryRead return false, which callers already treat as "nothing to restore".
The version belongs to the component, not to the game: a component whose payload shape changes in a way the serializer cannot tolerate (a member removed or reordered - adding one is fine) writes a higher version and switches on the value from TryRead<T>(byte[], out T, out byte).
public static class ComponentPayload
- Inheritance
-
objectComponentPayload
Fields
- CurrentVersion
Version stamped on payloads written by the current code (see the class remarks).
Methods
- TryRead<T>(byte[], out T)
Reads a payload written by Write<T>(T, byte). False means it is missing, empty, or not readable as
T- callers treat that as "nothing to restore" rather than an error, as they always have.
- TryRead<T>(byte[], out T, out byte)
Same, and also reports
versionso a component can migrate its own payload: switch on the value it finds here, read the older shape as its own older struct, and refuse a payload from the future withif (version > MyVersion) return;.
- VersionOf(byte[])
The version the payload was written with (0 when it is too short to hold one).
- Write<T>(T, byte)
Encodes a payload stamped with
version.