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

IExternalRootObject alternative for unmodifiable objects #87

Open
BreyerW opened this issue Sep 17, 2020 · 1 comment
Open

IExternalRootObject alternative for unmodifiable objects #87

BreyerW opened this issue Sep 17, 2020 · 1 comment
Assignees

Comments

@BreyerW
Copy link

BreyerW commented Sep 17, 2020

Currently im using json serializer (Json.net more specifically) but im investigating adding binary serializer as well for efficiency and when readability is not required.

I saw that you support external references which i consider to be very useful in my project but this feature require implementing interface on serialized object which is off-table.

So my question is are there alternatives to this interface that allow same or similar effect without requiring modifying serialized object?

If not i would like to request something akin to ReferenceResolver in Json.net. (basically abstract class that intercepts reference indentifiers when deserializing and produces them when serializing)

@rikimaru0345
Copy link
Owner

Currently implementing the interface is the only way.
But implementing an alternative as you described should be pretty easy:

  • Add a bool "SerializeAsExternalReference" to TypeConfig so we can use that instead of having to check for an interface (would also be a free performance improvement!).
  • Add an IReferenceResolver interface that gets stored in the SerializerConfig.
  • In ReferenceFormatter check if the TypeConfig (which we have to retreive anyway) has that newly added "external flag" set, and if so, then just call the reference resolver.

All of that could be implemented such that it would still be compatible with the old code.
Even better: Right now the external "ID" of an object is locked to being an int, but it doesn't have to be that way. In fact, we could make it so the reference resolver has full control over whats written.
That way the user has the option to save space (by writing a VarInt), or go the "easy way" (by writing a normal fixed 32bit int, just like is being done right now), or use some entirely different identifier (like a string or something)...

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