Skip to content
This repository was archived by the owner on May 16, 2022. It is now read-only.

Commit 58305ad

Browse files
committed
1.2.0
1 parent d857a27 commit 58305ad

File tree

28 files changed

+160
-61
lines changed

28 files changed

+160
-61
lines changed

README.md

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,97 @@ Versioning
111111
TODO...
112112

113113

114+
Union
115+
---
116+
ZeroFormatter supports Union type. It can define abstract class and `UnionAttributes`, `UnionKeyAttribute`.
117+
118+
```csharp
119+
public enum CharacterType
120+
{
121+
Human, Monster
122+
}
123+
124+
// UnionAttribute abstract type becomes Union, arguments is union subtypes.
125+
// It needs single UnionKey to discriminate
126+
[Union(typeof(Human), typeof(Monster))]
127+
public abstract class Character
128+
{
129+
[UnionKey]
130+
public abstract CharacterType Type { get; }
131+
}
132+
133+
[ZeroFormattable]
134+
public class Human : Character
135+
{
136+
// UnionKey property must mark [IgnoreFormat]
137+
// UnionKey value must return constant value(Type is free, you can use int, string, enum, etc...)
138+
[IgnoreFormat]
139+
public override CharacterType Type
140+
{
141+
get
142+
{
143+
return CharacterType.Human;
144+
}
145+
}
146+
147+
[Index(0)]
148+
public virtual string Name { get; set; }
149+
150+
[Index(1)]
151+
public virtual int Age { get; set; }
152+
153+
[Index(2)]
154+
public virtual int Faith { get; set; }
155+
}
156+
157+
[ZeroFormattable]
158+
public class Monster : Character
159+
{
160+
[IgnoreFormat]
161+
public override CharacterType Type
162+
{
163+
get
164+
{
165+
return CharacterType.Monster;
166+
}
167+
}
168+
169+
[Index(0)]
170+
public virtual string Race { get; set; }
171+
172+
[Index(1)]
173+
public virtual int Power { get; set; }
174+
175+
[Index(2)]
176+
public virtual int Magic { get; set; }
177+
}
178+
```
179+
180+
You can use Union as following.
181+
182+
```csharp
183+
var demon = new Monster { Race = "Demon", Power = 9999, Magic = 1000 };
184+
185+
// use UnionType(Character) formatter(be carefule, does not use concrete type)
186+
var data = ZeroFormatterSerializer.Serialize<Character>(demon);
187+
188+
var union = ZeroFormatterSerializer.Deserialize<Character>(data);
189+
190+
// you can discriminate by UnionKey.
191+
switch (union.Type)
192+
{
193+
case CharacterType.Monster:
194+
var demon2 = (Monster)union;
195+
demon2.Race.Is("Demon");
196+
demon2.Power.Is(9999);
197+
demon2.Magic.Is(1000);
198+
break;
199+
default:
200+
Assert.Fail("invalid");
201+
break;
202+
}
203+
```
204+
114205
for Unity
115206
---
116207
ZeroFormatter.Unity works on all platforms(PC, Android, iOS, etc...). But it can 'not' use dynamic serializer generation due to IL2CPP issue. But pre code generate helps it. Code Generator is located in `packages\ZeroFormatter.Interfaces.*.*.*\tools\zfc.exe`. zfc is using [Roslyn](https://github.com/dotnet/roslyn) so analyze source code, pass the target `csproj`.
@@ -386,6 +477,14 @@ Object is defined user own type. Class is lazy evaluation which has index header
386477
| Struct | [Index1Item:T1, Index2Item:T2,...] | Index is required begin from 0 and sequential. This layout includes KeyTuple, KeyValuePair. |
387478
| Struct? | [hasValue:bool(1)][Index1Item:T1, Index2Item:T2,...] | This layout includes KeyTuple?, KeyValuePair? and Tuple(C# Tuple is class but serialized in this format)|
388479

480+
**Union Format**
481+
482+
Union is eager evaluation, discriminated by key type to each value type.
483+
484+
| Type | Layout | Note |
485+
| ---- | ------ | ---- |
486+
| Union | [hasValue:bool(1)][unionKey:TKey][value:TValue] ||
487+
389488
**Dictionary Format**
390489

391490
Dictionary/MultiDictionary is eager evaluation. LazyDictionary/LazyMultiDictionary is lazy evaluation. All format are variable-length.

nuget/UnityReleases_1.1.1.zip

-4.61 MB
Binary file not shown.

nuget/Unity_Releases_1.2.0.zip

4.62 MB
Binary file not shown.

nuget/ZeroFormatter.Analyzer.nuspec

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@
22
<package xmlns="http://schemas.microsoft.com/packaging/2011/08/nuspec.xsd">
33
<metadata>
44
<id>ZeroFormatter.Analyzer</id>
5-
<version>1.0.6.0</version>
5+
<version>1.0.7.0</version>
66
<title>ZeroFormatter.Analyzer</title>
77
<authors>neuecc</authors>
88
<owners>y.neuecc</owners>
99
<projectUrl>https://github.com/neuecc/ZeroFormatter/</projectUrl>
1010
<requireLicenseAcceptance>false</requireLicenseAcceptance>
1111
<description>Analyzer of ZeroFormatter, verify rule for [ZeroFormattable] classes.</description>
12-
<releaseNotes>Support 1.1 WireFormat.</releaseNotes>
12+
<releaseNotes>Support 1.2 WireFormat.</releaseNotes>
1313
<tags>ZeroFormatter, analyzers</tags>
1414
<frameworkAssemblies>
1515
<frameworkAssembly assemblyName="System" targetFramework="" />

nuget/ZeroFormatter.Interfaces.nuspec

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@
22
<package xmlns="http://schemas.microsoft.com/packaging/2011/08/nuspec.xsd">
33
<metadata>
44
<id>ZeroFormatter.Interfaces</id>
5-
<version>1.1.1</version>
5+
<version>1.2.0</version>
66
<title>ZeroFormatter.Interfaces</title>
77
<authors>neuecc</authors>
88
<owners>y.neuecc</owners>
99
<projectUrl>https://github.com/neuecc/ZeroFormatter/</projectUrl>
1010
<requireLicenseAcceptance>false</requireLicenseAcceptance>
1111
<description>Plain interfaces and KeyTuple of ZeroFormatter, it is used for define serializable targets.</description>
12-
<releaseNotes>Support sequence wireformat.</releaseNotes>
12+
<releaseNotes>Support Union wireformat.</releaseNotes>
1313
<tags>ZeroFormatter, Serialization, Formatter, Serializer</tags>
1414
<frameworkAssemblies>
1515
<frameworkAssembly assemblyName="System" targetFramework=".NETFramework3.5" />

nuget/ZeroFormatter.Unity.nuspec

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,22 @@
22
<package xmlns="http://schemas.microsoft.com/packaging/2011/08/nuspec.xsd">
33
<metadata>
44
<id>ZeroFormatter.Unity</id>
5-
<version>1.1.1</version>
5+
<version>1.2.0</version>
66
<title>ZeroFormatter.Unity</title>
77
<authors>neuecc</authors>
88
<owners>y.neuecc</owners>
99
<projectUrl>https://github.com/neuecc/ZeroFormatter/</projectUrl>
1010
<requireLicenseAcceptance>false</requireLicenseAcceptance>
1111
<description>Infinitly fast serializer for .NET, .NET Core and Unity.</description>
12-
<releaseNotes>Support sequence wireformat.</releaseNotes>
12+
<releaseNotes>Support Union wireformat.</releaseNotes>
1313
<tags>ZeroFormatter, Serialization, Formatter, Serializer</tags>
1414
<frameworkAssemblies>
1515
<frameworkAssembly assemblyName="System" targetFramework="Unity Full v3.5" />
1616
<frameworkAssembly assemblyName="System.Core" targetFramework="Unity Full v3.5" />
1717
</frameworkAssemblies>
1818
<dependencies>
1919
<group targetFramework="Unity Full v3.5">
20-
<dependency id="ZeroFormatter.Interfaces" version="1.1.1" />
20+
<dependency id="ZeroFormatter.Interfaces" version="1.2.0" />
2121
</group>
2222
</dependencies>
2323
</metadata>

nuget/ZeroFormatter.nuspec

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,25 @@
22
<package xmlns="http://schemas.microsoft.com/packaging/2011/08/nuspec.xsd">
33
<metadata>
44
<id>ZeroFormatter</id>
5-
<version>1.1.1</version>
5+
<version>1.2.0</version>
66
<title>ZeroFormatter</title>
77
<authors>neuecc</authors>
88
<owners>y.neuecc</owners>
99
<projectUrl>https://github.com/neuecc/ZeroFormatter/</projectUrl>
1010
<requireLicenseAcceptance>false</requireLicenseAcceptance>
1111
<description>Infinitly fast serializer for .NET, .NET Core and Unity.</description>
12-
<releaseNotes>Support sequence wireformat.</releaseNotes>
12+
<releaseNotes>Support Union wireformat.</releaseNotes>
1313
<tags>ZeroFormatter, Serialization, Formatter, Serializer</tags>
1414
<frameworkAssemblies>
1515
<frameworkAssembly assemblyName="System" targetFramework=".NETFramework4.5" />
1616
<frameworkAssembly assemblyName="System.Core" targetFramework=".NETFramework4.5" />
1717
</frameworkAssemblies>
1818
<dependencies>
1919
<group targetFramework=".NETFramework4.5">
20-
<dependency id="ZeroFormatter.Interfaces" version="1.1.1" />
20+
<dependency id="ZeroFormatter.Interfaces" version="1.2.0" />
2121
</group>
2222
<group targetFramework=".NETStandard1.6">
23-
<dependency id="ZeroFormatter.Interfaces" version="1.1.1" />
23+
<dependency id="ZeroFormatter.Interfaces" version="1.2.0" />
2424
<dependency id="System.Reflection.Emit" version="4.0.1" />
2525
<dependency id="System.Runtime" version="4.1.0" />
2626
<dependency id="System.Runtime.Extensions" version="4.1.0" />

nuget/push.bat

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
nuget push ZeroFormatter.Analyzer.1.0.6.0.nupkg -Source https://www.nuget.org/api/v2/package
2-
nuget push ZeroFormatter.1.1.1.nupkg -Source https://www.nuget.org/api/v2/package
3-
nuget push ZeroFormatter.Interfaces.1.1.1.nupkg -Source https://www.nuget.org/api/v2/package
4-
nuget push ZeroFormatter.Unity.1.1.1.nupkg -Source https://www.nuget.org/api/v2/package
1+
nuget push ZeroFormatter.Analyzer.1.0.7.0.nupkg -Source https://www.nuget.org/api/v2/package
2+
nuget push ZeroFormatter.1.2.0.nupkg -Source https://www.nuget.org/api/v2/package
3+
nuget push ZeroFormatter.Interfaces.1.2.0.nupkg -Source https://www.nuget.org/api/v2/package
4+
nuget push ZeroFormatter.Unity.1.2.0.nupkg -Source https://www.nuget.org/api/v2/package

nuget/zfc.exe

19 KB
Binary file not shown.

sandbox/PerformanceComparison/Properties/AssemblyInfo.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,5 +32,5 @@
3232
// You can specify all the values or you can default the Build and Revision Numbers
3333
// by using the '*' as shown below:
3434
// [assembly: AssemblyVersion("1.0.*")]
35-
[assembly: AssemblyVersion("1.1.1.0")]
36-
[assembly: AssemblyFileVersion("1.1.1.0")]
35+
[assembly: AssemblyVersion("1.2.0.0")]
36+
[assembly: AssemblyFileVersion("1.2.0.0")]

0 commit comments

Comments
 (0)