High performance object serialization library supporting sum types

I wonder if any of the high-performance serialization libraries (like Google protocol buffers) support sum types .

Sum types are tagged unions, basically the ability to say something is either A, B, or C. Sum types are used in languages ​​like Haskell and ML that support Algebraic data types.

+6
source share
3 answers

If “like Google’s protocol buffers,” you mean the ability to generate code for multiple languages, then this probably doesn’t exist. Emulation of types of sums in languages ​​that do not support them is inconvenient at best (try matching the template by boost: option, for example). Therefore, it makes sense to leave them if the main goal is the main languages.

If you are satisfied using only haskell / ocaml / all kinds of choices. Haskell has cereal , binary , safecopy, and possibly others. There is a piqi project for ocaml .

+2
source

I do not know any practical systems that support types of sums other than Piqi (I am the author). Piqi is compatible with protocol buffers and supports OCaml and Erlang. The absence of sum types in protocol buffers was one of the reasons I created it.

My plan is to extend Piqi to support other languages ​​like Haskell, Clojure, etc.

+2
source

Is there a need for a "high-performance" format? Many general-purpose formats should be able to simply use existing constructs - in particular, Maps / hashtables to support alliances (just include a record with a key indicating the type of actual value). So maybe you could just use a simple convention to use, say, JSON, to transfer such content.

0
source

Source: https://habr.com/ru/post/908977/


All Articles