Serializing and deserializing complex structures