All Projects → dre0dru → LocalStorage

dre0dru / LocalStorage

Licence: MIT license
Configurable generic class for managing local data saved on device.

Programming Languages

C#
18002 projects

Projects that are alternatives of or similar to LocalStorage

serde
🚝 (unmaintained) A framework for defining, serializing, deserializing, and validating data structures
Stars: ✭ 49 (+104.17%)
Mutual labels:  serialization
cattrs
Complex custom class converters for attrs.
Stars: ✭ 565 (+2254.17%)
Mutual labels:  serialization
parco
🏇🏻 generalist, fast and tiny binary parser and compiler generator, powered by Go 1.18+ Generics
Stars: ✭ 57 (+137.5%)
Mutual labels:  serialization
CSharpCompilerSettingsForUnity
Change the C# compiler (csc) used on your Unity project, as you like!
Stars: ✭ 208 (+766.67%)
Mutual labels:  upm-package
fdat.cljc
Function serialization between Clojure processes and dialects
Stars: ✭ 49 (+104.17%)
Mutual labels:  serialization
NBT
A java implementation of the NBT protocol, including a way to implement custom tags.
Stars: ✭ 128 (+433.33%)
Mutual labels:  serialization
bytecodec
A tiny Rust framework for implementing encoders/decoders of byte-oriented protocols
Stars: ✭ 21 (-12.5%)
Mutual labels:  serialization
coqpit
Simple but maybe too simple config management through python data classes. We use it for machine learning.
Stars: ✭ 67 (+179.17%)
Mutual labels:  serialization
c-plus-plus-serializer
A minimal C++11 header only serializer. Can serialize basic types, strings, containers, maps and custom classes. No suppprt yet for pointer types.
Stars: ✭ 36 (+50%)
Mutual labels:  serialization
elm-protobuf
protobuf plugin for elm
Stars: ✭ 93 (+287.5%)
Mutual labels:  serialization
serial-builder
Library for manually creating Java serialization data.
Stars: ✭ 20 (-16.67%)
Mutual labels:  serialization
borsh-rs
Rust implementation of Binary Object Representation Serializer for Hashing
Stars: ✭ 149 (+520.83%)
Mutual labels:  serialization
GenericProtocol
⚡️ A fast TCP event based buffered server/client protocol for transferring data over the (inter)net in .NET 🌐
Stars: ✭ 38 (+58.33%)
Mutual labels:  serialization
flextool
C++ compile-time programming (serialization, reflection, code modification, enum to string, better enum, enum to json, extend or parse language, etc.)
Stars: ✭ 32 (+33.33%)
Mutual labels:  serialization
moonblob
Binary serialization for moonscript + LuaJIT
Stars: ✭ 22 (-8.33%)
Mutual labels:  serialization
wasmbin
A self-generating WebAssembly parser & serializer in Rust.
Stars: ✭ 40 (+66.67%)
Mutual labels:  serialization
unity-now
▲ Vercel Now plugin for Unity. Deploy WebGL builds with ease
Stars: ✭ 21 (-12.5%)
Mutual labels:  upm-package
Unity-Interface-Support
A simple implementation which allows for interface-type fields to be accepted in the Unity inspector.
Stars: ✭ 45 (+87.5%)
Mutual labels:  serialization
moko-network
Network components with codegeneration of rest api for mobile (android & ios) Kotlin Multiplatform development
Stars: ✭ 107 (+345.83%)
Mutual labels:  serialization
avrow
Avrow is a pure Rust implementation of the avro specification https://avro.apache.org/docs/current/spec.html with Serde support.
Stars: ✭ 27 (+12.5%)
Mutual labels:  serialization

openupm

Description

Configurable generic classes for managing local data saved on device. Unity 2020.1+

Features

  • Two generic classes with configuration options for data read/write and serialization/deserialization via file system or player prefs.
  • Simple file provider that just reads/writes data.
  • Data transformations that allow to preprocess data on read/write:
    • IDataTransform that uses AES encryption to encrypt/decrypt data.
    • IDataTransform that uses GZip or Deflate to compress/decompress data.
  • Json serialization provider that uses JsonUtility for serialization.
  • File storage saves data to Application.persistentDataPath.
  • Player prefs storage saves data to PlayerPrefs. Data location depends on device, refer to Unity documentation.
  • Easy to use and understand abstractions that allow to create custom serialization/deserialization and data transformation processes.
  • Async/sync API.
  • Optional UniTask support for async API.

Installation

This package can be installed as unity module directly from git url in two ways:

  • By adding following line in Packages/manifest.json:
"com.dre0dru.localstorage": "https://github.com/dre0dru/LocalStorage.git#upm",
  • By using Window/Package Manager/Add package from git URL... in Unity:
https://github.com/dre0dru/LocalStorage.git#upm
openupm add com.dre0dru.localstorage

Optional UniTask support

UniTask package can be installed to convert async API from using Task to UniTask. No further actions are required after installation.

UniTask support can be disabled by using DISABLE_UNITASK_SUPPORT define.

Usage

FileStorage usage

//Serialization/deserialization implementation
ISerializationProvider serializationProvider = new UnityJsonSerializationProvider();

//Path to save/load from (optional)
string path = "dataFolder";  //Resulting path will be Application.persistentDataPath/dataFolder
//File save/load implementation
IFileProvider fileProvider = new FileProvider(path);

IFileStorage storage = new FileStorage(serializationProvider, fileProvider);

string fileName = "fileName.extension";

//Resulting path will be Application.persistentDataPath/dataFolder/fileName.extension
string filePath = storage.GetFilePath(fileName);

//Serializes data then saves file
storage.Save(new Vector2(1.0f, 1.0f), fileName);

//Async saving
await storage.SaveAsync(new Vector2(1.0f, 1.0f), fileName);

//Check if file exists
bool exists = storage.FileExists(fileName);

//Loads file then deserializes data
Vector2 deserialized = storage.Load<Vector2>(fileName);

//Async loading
Vector2 deserialized = await storage.LoadAsync<Vector2>(fileName);

//Deletes file if present
storage.Delete(fileName);

PlayerPrefsStorage usage

//Serialization/deserialization implementation
ISerializationProvider serializationProvider = new UnityJsonSerializationProvider();

IPlayerPrefsStorage storage = new PlayerPrefsStorage(serializationProvider);

string dataKey = "key";

//Serializes data using ISerializationProvider then puts it into PlayerPrefs under provided key
storage.SetData(dataKey, new Vector2(1, 1));

//Async saving
await storage.SetDataAsync(dataKey, new Vector2(1, 1));

//Loads data from PlayerPrefs by key then deserializes using ISerializationProvider
Vector2 deserialized = storage.GetData<Vector2>(dataKey);

//Async loading
Vector2 deserialized = await storage.GetDataAsync<Vector2>(dataKey);

The rest of IPlayerPrefsStorage API mimics Unity PlayerPrefs API.

Warning! PlayerPrefsStorage is not thread safe.

Data transformation usage

IDataTransform implementations can be used to preprocess data during serialization/deserialization process. Available data transformations are:

  • AesEncryptionDataTransform
  • DeflateDataTransform
  • GZipDataTransform
//This is just an example, don't generate new key/IV every time
public class ExampleEncryptionSettings : IEncryptionSettings
{
    public byte[] Key { get; private set; }
    public byte[] InitializationVector { get; private set; }

    public ExampleEncryptionSettings()
    {
        //Create AES instance
        using var aes = Aes.Create();
        //Save AES key somewhere
        Key = aes.Key;
        //Save AES IV somewhere
        InitializationVector = aes.IV;
    }
}

//Encryption settings for AES
IEncryptionSettings encryptionSettings = new ExampleEncryptionSettings();

//Setup desired IDataTransform implementation
IDataTransform encryptionDataTransform = new AesEncryptionDataTransform(encryptionSettings);

//Base ISerializationProvider that will be used before/after data transform is applied
ISerializationProvider baseSP = new UnityJsonSerializationProvider();

//Setup ISerializationProvider that will use target data transformation during serialization/deserialization process
ISerializationProvider transformSerializationProvider =
    new DataTransformSerializationProvider(baseSP, encryptionDataTransform);

//Use DataTransformSerializationProvider with FileStorage
IFileProvider fp = new FileProvider();
IFileStorage fileStorage = new FileStorage(transformSerializationProvider, fp);

//Or with PlayerPrefsStorage
IPlayerPrefsStorage playerPrefsStorage = new PlayerPrefsStorage(transformSerializationProvider);

You can combine multiple IDataTransform to create chained data transformations:

IEncryptionSettings encryptionSettings = new ExampleEncryptionSettings();

//Encryption data transform
IDataTransform encryptionDataTransform = new AesEncryptionDataTransform(encryptionSettings);

//Compression data transform
IDataTransform compressionDataTransform = new GZipDataTransform();

//Create combined data transform
//First it will encrypt data, then it will compress the result
IDataTransform combinedDataTransform = new CombinedDataTransform(encryptionDataTransform, compressionDataTransform);

//Pass it to DataTransformSerializationProvider implementation
ISerializationProvider serializationProvider =
    new DataTransformSerializationProvider(new UnityJsonSerializationProvider(),
        combinedDataTransform);

//Data transformation chains can be created indefinitely
IDataTransform customDataTransform = new CustomDataTransform();

//This will result in applying CustomDataTransform data transformations first,
//then applying data transformations specified by combinedDataTransform instance
IDataTransform multipleCombinedDataTransform =
    new CombinedDataTransform(customDataTransform, combinedDataTransform);

Sync/async API

All interfaces come in 3 variants:

  • Sync API
  • Async API
  • Both sync and async

Implementations that depends on mentioned interfaces have same 3 variants, e.g. FileStorage for both sync and async API, FileStorageSync for sync API only and FileStorageAsync for async API only.

License

The software released under the terms of the MIT license.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].