serializer runtime type checking?
when writing a Serializer and Deserializer, how would i go about ensuring stuff written and read in the correct order and with expected read sizes and positions (eg in case serializing misses a field that is otherwise written)
eg
6 Replies
for example
we might read this back incorrectly due to needing to serialize so many fields
we might miss a field or two when writing the ReadSKPaint method to deserialize this
or we might accidentally get the order wrong
I take it you just wanted to share that with us and don't have a question?
is there way to verify/check such when writing these methods?
possibly at runtime?
eg
read_incorrect_field() // generates an error at runtime if field length and position differs from the one written
That's basically your job, as a dev, to ensure you're not missing any. Unit tests would be a way to increase your confidence in your code, and no, it doesn't execute at run time.
If you want to ensure the input is in the proper format, that's a different thing.
You would go about it the same way as you would in any other method.
But given the context, I do have to wonder why you're not using an existing serializer.
for example
WriteInt(); // write at position 0
ReadSingle(); // read at position 0 but would error at runtime due to incorrect type and/or size
kinda like runtime type checking but for serialized data i guess
cus i dont have access to the source code
(eg i cannot simply make it [Serializable])
but i CAN manually serialize it
anyway are there any kind of serializers that do this kind of checking?
something like this, which the Reader will verify when reading and error if it detects it is attempting to read an incorrect type and incorrect length