Snippet for serialization of any primitive type

https://gist.github.com/iamed2/7800a9b391d9e11f0f2b7fbbfbb84c32

I recently came up with this for InlineString and realized it is nearly universally applicable for primitive types.

Standard library Julia serialization works well by default for primitive types, and will just call read and write. If you have simple symmetric read and write functions for your primitive types, you should be good to go without these additional methods.

If for some reason you:

  • don’t have or want both read and write functions
  • have read and write functions that aren’t round-trippable
  • have read and write functions that transform the data before writing in a way that is either expensive or produces an inefficient data representation

then this serialization method may be right for you!

1 Like