Arch.Persistence
Arch.Persistence, a tiny persistence framework that supports JSON & Binary.
JSON
// Initialize the Serializer, and inject custom ones to handle classes or structs in a specific way.
var serializer = new ArchJsonSerializer(new SpriteSerializer{GraphicsDevice = GraphicsDevice}, ...);
var worldJson = serializer.ToJson(_world); // Serialize your world to a json-string
_world = serializer.FromJson(worldJson); // Deserialize it from a json-string.
var entityJson = serializer.ToJson(_world, someEntity); // Serialize single Entity to json.
serializer.FromJson(_world, entityJson); // Entity is being deserialized to the given world.
// Example Custom Serializer for Sprites
public class SpriteSerializer : IJsonFormatter<Sprite>
{
public void Serialize(ref JsonWriter writer, Sprite value, IJsonFormatterResolver formatterResolver)
{
// Your logic
}
public Sprite Deserialize(ref JsonReader reader, IJsonFormatterResolver formatterResolver)
{
// Your logic
}
}Binary
Last updated