You have waay too many explicit type checks and custom functions for writing. Use write(io, num, T::Number)
instead of writenum(io, num, T)
. write(io, str::String)
instead of writestr(io, str)
. Use dispatch to your advantage, not to build explicit ifelse
trees.
In reading, having a table converting tags to types is fine, but again - use dispatch to your advantage. read(io, T::Number)
instead of readnum(io, T)
. Call it via tag = read(io, UInt8); read(io, tag2type[tag]
instead of manually doing ifelse
s.
I think I’ve read your thread on that topic and I seem to remember that the code you’ve posted here was not one of the recommended ways of doing what you’re thinking of. Probably best for another topic though, would get OT here.