asynkron / Wire

Binary serializer for POCO objects

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Support custom layout

mookid8000 opened this issue · comments

Similar to how #19 can be used to reduce the overhead of frequently occurring values with very little actual data, another mechanism can reduce the overhead of value types even more.

The example given in #19 is actually a little bit artificial, since I usually end up adding a custom converter for my (usually) tiny value types.

With a custom converter, the data otherwise serialized as

{
    "$type": "SomeProject.SomeComponent.SomeNamespace.Values.Date, SomeProject.SomeComponent",
    "Day": 3,
    "Month": 3,
    "Year": 2016
}

is serialized as

"2016/3/3"

(which can be done because JSON.NET can infer the type Date and the custom converter has all the necessary serialization roundtripping code).

Could it be an idea for Wire to support something similar, so that the data otherwise serialized as

SomeProject.SomeComponent.SomeNamespace.Values.Date, SomeProject.SomeComponent
08 # int
0003
08 # int
0003
08 # int
07E0

could be reduced to

*Date
07 # string
??? # some length stuff
20160303 # the actual string

?

This is already supported through surrogates.
See https://github.com/rogeralsing/Wire/blob/master/Wire.Tests/SurrogateTests.cs for some examples.

Surrogates allow you to replace the type being serialized with a custom one which is more wire friendly. just like the example above.
This is bidirectional so you can go from real type to surrogate and from surrogate to real type when serializing/deserializing.

:+1: I was confused by the surrogates, but now I get it :smile: