Typeclasses for binary serialization in PureScript.
Note: Although this library shares a lot of features similar to the cereal library from Haskell, it is not yet compatible.
It should feel fairly similar to Argonaut, but with a
binary spin on things - everything is very Effect-ful, and will throw errors if something doesn't line-up as expected.
Just implement the EncodeArrayBuffer and DecodeArrayBuffer typeclasses to support binary serialization for
your data type.
- The
Arrayinstance first packs its length as a 4-byteUint32BE- I don't know of a perfect way around this without excessive testing. - The
CharandCodePointinstances seem to reflect utf-8 pretty decently - Woo Hoo! Pure utf-8 serialization!! But wait... - The
Stringinstance just turns it into anArray CodePoint, so there's an initial word denoting the string's length. Right now, I don't know of a clean way around this, without making every instance have a length argument. - The
Vecinstance actually sidesteps the length argument, because the length is assumed to be known at compile-time. - The
ArrayBuffer,DataView, andArrayViewinstances also have a similar initial length argument. Writing is not as efficient as you'd hope. - The
Recordinstance first turns the record into anObject ArrayBuffer, which then becomes aArray (Tuple String ArrayBuffer)- it's not super efficient. - The
Genericinstances treat everySumas its own distinguished, isolated possability - for data types with multiple consecutive sum values, likeTheseorOrdering, it's suggested to write your own instance to pack each sum constructor as its own flag in the byte range0 - 255.Sums are treated likeEither- only0and1are used.