BinarySerialization - need some design help
Hi, this is my first foray into lower level programming and I could use some help.
I am writing a DOCSIS-compliant binary serializer for C#. It will take as input a
This is a barebones, minified example of what these files will contain. Every line is either a property or a collection of properties.
I will refer to these properties as
Now the issue I am facing is that there are 25 ish encoding methods and 25 decoding methods, but hundreds of different properties. All unique properties are stored in a property map with name, id and a reference to the correct method for encoding or decoding.
This can be seen here: https://github.com/rlaager/docsis/blob/master/src/docsis_symtable.h
My original idea was that when I am parsing a file, I can initialize a new
I am writing a DOCSIS-compliant binary serializer for C#. It will take as input a
.cfg or .txt file that resembles a JSON, but is a bit different:This is a barebones, minified example of what these files will contain. Every line is either a property or a collection of properties.
I will refer to these properties as
DocsisProperty<T>, since they will be deserialized into a C# type and then encoded into byte[] later on.Now the issue I am facing is that there are 25 ish encoding methods and 25 decoding methods, but hundreds of different properties. All unique properties are stored in a property map with name, id and a reference to the correct method for encoding or decoding.
This can be seen here: https://github.com/rlaager/docsis/blob/master/src/docsis_symtable.h
My original idea was that when I am parsing a file, I can initialize a new
DocsisProperty<T> based on the identifier of the value, then later on when I want to encode it I call docsisProperty.Encode(), and it will look up some static dictionary to figure out which encoding method is the appropriate one. However that gets complicated quickly because of the generic type on DocsisProperty<T>. The dictionary would then have to use object or dynamic as it's return type, and I am not a fan of either approach.