Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support custom layout #20

Closed
mookid8000 opened this issue Mar 3, 2016 · 2 comments
Closed

Support custom layout #20

mookid8000 opened this issue Mar 3, 2016 · 2 comments

Comments

@mookid8000
Copy link

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

?

@rogeralsing
Copy link
Collaborator

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.

@mookid8000
Copy link
Author

👍 I was confused by the surrogates, but now I get it 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants