Persist 1.0.0.0 released

Persist is a binary serialization library with two aims

  1. Have a default serialization format that can simply be derived for most types using Generic
  2. Allow a type to have a custom serialization format that matches an external specification.

Most of the improvements with this release were for goal 2. There is now support for backpatching a length value and avoid a 2nd data-structure walk. This is useful with tag-length-value formats where the length is a fixed number of bytes. It is also a source for some performance improvements with the default format for the builtin list datatype. There is additional support for de-serializing these formats as well with the new getPrefix unsafeGetPrefix helpers.

The API is similar enough to binary and cereal that it should be easy enough to try out the library.

9 Likes

Generic

inb4 compile time fearmonger pearl clutching (lmaooo)

On a serious note tho

Includes utilities to match externally specified data formats.

I couldn’t find this in the module haddocks. What does this mean exactly? Could I use this library to handle a binary format like UBJSON? or is that not what “externally specified” means here?

That is the kind of thing meant by “externally specified.” I intend to use these new features in the cql library to match the cassandra encoding.

For example, all of the numbers in UBJSON are written in big-endian format. You would want to use putBE for them. The default is little-endian if you use the default via Generic.

The API bits I would consider useful for external formats are:

  • putLE/putBE
  • reserveSize/resolveSize*
  • getPrefix

There is currently no lookahead or backtracking, so depending on the binary format it may be difficult to make it fit. Lookahead would be relatively easy to implement with the exposed internals.

1 Like

Can you add instances for Generically (Programming & Proving by Jan van BrĂĽgge).

2 Likes

The defaults rely on Generic, but can be easily overridden. If there were a PR that explained why Generically was useful, I’d be happy to merge and re-release.