Hello senior developers ,
my plugin requires:
- Read/write geometry, metadata and global configuration in Rhino and Grasshopper for runtime operations. (main)
- Read/write to disk, 3dm and others.
- Web communication.
Is there a way to unify everything in a single format? For example, I could use JSON as a funnel for those needs? Do you think it’s worth it, if the top priority is minimizing development time and clean code, rather than the efficiency that specialization gives? Would it have significant downsides? Or is it better to convert binary to Base64 in the json?
The design idea is to have an interface that forces objects to serialise and have a static class that takes care of the operation, and different classes call this static class for specific (de)serialization cases.
I have discarded System.Runtime.ISerializable and its implementation with attributes because I don’t like it and found that using ISerializationSurrogate and ISurrogateSelector I can use any System.Runtime.Serialization.IFormatter and define it in each object with GetObjectData(info, context) and SetObjectData(info, context), so I have the conversion to binary and potentially others implementing IFormatter. Should I go this way and convert to Base64 in the json?
I had started my plugin using System.Xml.Linq and later I was forced to use JSON as well, so my custom formatter (inspired by GH_IO) didn’t achieve its goal of unifying communication with the database, pasting an xml into a json or converting it to binary and then converting it to text to put it in a json seemed pretty ugly to me… But due to a drastic change in my objects I have to redefine all this and I wanted to ask you what would you choose, and in that case, what library and classes would you recommend.
I would like to integrate it as much as possible with the Rhino ecosystem, that’s why I’m asking in this forum. I don’t know your recommendations for the different serialisation cases. I don’t know if I should use Rhino.FileIO.BinaryArchiveWriter/Reader because I don’t know how generalizable it is or if it is useful beyond (de)serializing custom objects.