lazydata.superlazy
0.1.0
See the version list below for details.
dotnet add package lazydata.superlazy --version 0.1.0
NuGet\Install-Package lazydata.superlazy -Version 0.1.0
<PackageReference Include="lazydata.superlazy" Version="0.1.0" />
paket add lazydata.superlazy --version 0.1.0
#r "nuget: lazydata.superlazy, 0.1.0"
// Install lazydata.superlazy as a Cake Addin #addin nuget:?package=lazydata.superlazy&version=0.1.0 // Install lazydata.superlazy as a Cake Tool #tool nuget:?package=lazydata.superlazy&version=0.1.0
LazyData
A quick data (de)serialization framework for varying data formats in .net with a focus on clean and minimal serialized output for each format, mainly for game development scenarios such as in Unity, MonoGame etc.
Formats supported
- Json (via some JSON.Net implementation)
- Xml
- Binary
If you are interested in how the outputs would look take a look here
Examples
If you are SUPER lazy you can use the SuperLazy.Transformer
to get stuff done like a typical serialization framework:
var modelIn = new SomeModel();
var data = Transformer.ToJson(modelIn);
var modelOut = Transformer.FromJson(data);
You can even lazily transform your data between formats on the fly, which is helpful if you debug in JSON but want to use Binary for production, here is an example of one of the tests:
var model = SerializationTestHelper.GeneratePopulatedModel();
var expectdString = Transformer.ToJson(model);
var xml = Transformer.FromJsonToXml(expectdString);
var binary = Transformer.FromXmlToBinary(xml);
var json = Transformer.FromBinaryToJson(binary);
Assert.AreEqual(expectdString, json);
Non Lazy Approach
The static transformer is there for people who dont care about customizing the library and just want to (de)serialize everything however the library was built to be configurable so you can skip the helper Transformer
class and make the serializers yourself like so:
public class SomeClass
{
public float SomeValue { get; set; }
}
var mappingRegistry = new MappingRegistry(new EverythingTypeMapper());
var serializer = new JsonSerializer(_mappingRegistry);
var output = serializer.Serialize(model);
Console.WriteLine("FileSize: " + output.AsString.Length + " bytes");
Console.WriteLine(output.AsString);
Deserialize stuff
var someDataFromAFile = getData();
var dataObject = new DataObject(someDataFromAFile);
var mappingRegistry = new MappingRegistry(new EverythingTypeMapper());
var deserializer = new JsonSerializer(_mappingRegistry);
var model = deserializer.Deserialize<TypeOfModel>(dataObject);
You can alternatively use an DefaultTypeMapper
instead of the EverythingTypeMapper
which will only attempt to serialize things with attributes on. The allowing you to not need any custom attributes. This is handy for scenarios where you just treat your models as pure data classes.
Only serialize certain properties
[Persist]
public class SomeClass
{
[PersistData]
public float SomeValue { get; set; }
public string NotPersisted { get; set; }
}
var mappingRegistry = new MappingRegistry(new DefaultTypeMapper());
var serializer = new JsonSerializer(_mappingRegistry);
var output = serializer.Serialize(model);
Console.WriteLine("FileSize: " + output.AsString.Length + " bytes");
Console.WriteLine(output.AsString);
The [Persist]
attribute indicates that this should be output in the serialized data, on a class it indicates it is a root object that contains serialized data, on a property it indicates the property should be mapped.
This attribute is used rather than [Serialize]
because it is due to it being originally meant for ETL processes, if you want to just treat it like a serialization framework you can bypass the need for attributes entirely.
Docs
Check out the docs directory for docs which go into more detail.
Tests
There are a suite of unit tests which verify most scenarios, as well as output some performance related stats, it is recommended you take a peek at them if you want to see more advanced scenarios.
Blurb
This was originally part of the Persistity library for unity (which was originally part of EcsRx library), however was separated out to make more generic and reuseable and although its still meant to be used as a smaller part of a larger process, it has some helpers to allow it to be used just like a basic serializer without much effort.
The original focus of this library was to provide a consistent way to pass data around and convert/transform it between formats and types easily however as the serialization pieces can be used in isolation purely for serialization
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
.NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
.NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen40 was computed. tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
-
- lazydata (>= 0.1.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|---|---|
3.0.17 | 1,030 | 3/18/2020 |
2.0.11 | 1,064 | 12/19/2018 |
2.0.9 | 1,043 | 11/26/2018 |
1.1.7 | 1,174 | 11/15/2018 |
1.0.5 | 1,080 | 11/7/2018 |
1.0.3 | 1,101 | 11/7/2018 |
0.3.2 | 1,175 | 9/20/2018 |
0.3.1 | 1,159 | 9/20/2018 |
0.3.0 | 1,203 | 9/20/2018 |
0.2.21 | 1,109 | 9/18/2018 |
0.2.20 | 1,129 | 9/18/2018 |
0.2.19 | 1,135 | 9/18/2018 |
0.2.0 | 1,176 | 9/12/2018 |
0.1.0 | 1,582 | 2/16/2018 |
Initial release