rikimaru0345 / Ceras

Universal binary serializer for a wide variety of scenarios https://discord.gg/FGaCX4c
MIT License
484 stars 53 forks source link

IExternalRootObject alternative for unmodifiable objects #87

Open BreyerW opened 4 years ago

BreyerW commented 4 years ago

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 commented 4 years ago

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

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)...