Serialisation – Arma Reforger
m (Add warning about parameterless constructor and rename context to make the example easy to copy paste) |
Lou Montana (talk | contribs) m (Some wiki formatting) |
||
(5 intermediate revisions by 2 users not shown) | |||
Line 1: | Line 1: | ||
{{TOC|side}} | {{TOC|side}} | ||
This page | This page explains serialisation using {{Link/Enfusion|armaR|SCR_JsonSaveContext}}/{{Link/Enfusion|armaR|SCR_JsonLoadContext}} and {{Link/Enfusion|armaR|SCR_BinSaveContext}}/{{Link/Enfusion|armaR|SCR_BinLoadContext}}. | ||
== JSON == | == JSON == | ||
{{Feature|informative| | |||
* Passing an empty string as the name parameter into <enforce inline>BaseSerializationSaveContext.WriteValue()</enforce> or <enforce inline>BaseSerializationLoadContext.ReadValue()</enforce> allows for a complex top-level struct to be written/read. | |||
* See also {{Link|Arma Reforger:JsonApiStruct Usage|JsonApiStruct Usage}}. | |||
}} | |||
=== Serialisation === | === Serialisation === | ||
Line 72: | Line 77: | ||
The following class set to serialise will serialise all its properties. | The following class set to serialise will serialise all its properties. | ||
{{Feature|warning|Data structures that shall be serialised are not allowed to have parameters in their constructor | {{Feature|warning|Data structures that shall be serialised are not allowed to have parameters in their constructor, otherwise they can not be read back.}} | ||
<enforce> | <enforce> | ||
Line 80: | Line 85: | ||
protected string m_sVariable; | protected string m_sVariable; | ||
protected float m_fVariable = 33.3; | protected float m_fVariable = 33.3; | ||
} | } | ||
</enforce> | </enforce> | ||
Line 93: | Line 98: | ||
[NonSerialized()] | [NonSerialized()] | ||
protected float m_fVariable = 33.3; | protected float m_fVariable = 33.3; | ||
} | } | ||
</enforce> | </enforce> | ||
Line 115: | Line 120: | ||
if (!context.IsValid()) | if (!context.IsValid()) | ||
return false; | return false; | ||
context.WriteValue("theString", m_sVariable); | context.WriteValue("theString", m_sVariable); | ||
context.WriteValue("integer", m_iVariable); | context.WriteValue("integer", m_iVariable); | ||
Line 122: | Line 127: | ||
return true; | return true; | ||
} | } | ||
} | } | ||
</enforce> | </enforce> | ||
Line 146: | Line 151: | ||
return true; | return true; | ||
} | } | ||
} | } | ||
</enforce> | </enforce> | ||
{{GameCategory|armaR|Modding|Tutorials|Scripting}} | {{GameCategory|armaR|Modding|Tutorials|Scripting}} |
Latest revision as of 10:11, 30 September 2024
This page explains serialisation using SCR_JsonSaveContext/SCR_JsonLoadContext and SCR_BinSaveContext/SCR_BinLoadContext.
JSON
Serialisation
Deserialisation
Binary
Serialisation
Deserialisation
Object Serialisation
Simple
The following class set to serialise will serialise all its properties.
NonSerialized
Adding the NonSerialized() decorator to a field will make the serialisation ignore it.
Advanced
The following methods allow to define a custom serialisation per class. This is useful to avoid saving lengthy yet useless information for loading as well as load values in a certain order.
SerializationSave
If an object has the SerializationSave method defined, the SaveContext will use it and not process object's properties automatically at all.
SerializationLoad
If an object has the SerializationLoad method defined, the SaveContext will use it and not process object's properties automatically at all.