This package provides serialization/deserialization utilities for ArrayBuffer. It is useful for implementing encoder/decoder for you data structure.
Serial Model
Serializer and Deserializer work on Builder model. It has these primitives below:
i8/u8
i16/u16
i32/u32
i64/u64
And also serializing string as UTF-8 sequence is supported by encUtf8/decUtf8, as a composite builder.
Their features are provided as each monad, monadForCodeM and monadForDecoder respectively. So you can combine them with using these monads and CatT system.
Encoder
An Encoder<T> denotes that a function transforming data T to a Code, which writes bytes to an ArrayBuffer through DataView.
There are utility functions to encode primitive data:
Basics
encUnit - Does nothing
encSum - Useful to encode a sum type
Numerics
encI8/encU8
encI16Be / encI16Le / encU16Be / encU16Le
encI32Be / encI32Le / encU32Be / encU32Le
encI64Be / encI64Le / encU64Be / encU64Le
encF32Be / encF32Le
encF64Be / encF64Le
String
encUtf8
And internal others exported
Also you can compose and customize encoders by CodeM's monad to create your own encoder like this:
Note that you need to match the process orders of your encoder and decoder, because it reads/writes a binary sequence by written order. If you consider the version of your data, you may use Envelope to append a version.
This package provides serialization/deserialization utilities for
ArrayBuffer. It is useful for implementing encoder/decoder for you data structure.Serial Model
SerializerandDeserializerwork onBuildermodel. It has these primitives below:And also serializing
stringas UTF-8 sequence is supported byencUtf8/decUtf8, as a composite builder.Their features are provided as each monad,
monadForCodeMandmonadForDecoderrespectively. So you can combine them with using these monads andCatTsystem.Encoder
An
Encoder<T>denotes that a function transforming dataTto aCode, which writes bytes to anArrayBufferthroughDataView.There are utility functions to encode primitive data:
encUnit- Does nothingencSum- Useful to encode a sum typeencI8/encU8encI16Be/encI16Le/encU16Be/encU16LeencI32Be/encI32Le/encU32Be/encU32LeencI64Be/encI64Le/encU64Be/encU64LeencF32Be/encF32LeencF64Be/encF64LeencUtf8Also you can compose and customize encoders by
CodeM's monad to create your own encoder like this:Note that an
Encoderserializes lazily. You need pass aCodetorunCodeto evaluate it.Decoder
A
Decoder<T>denotes that a function parsingCodeto dataT.There are utility functions to decode primitive data:
decSum- Useful to decode a sum typefailDecoder- Useful to report decoding errordecI8/encU8decI16Be/decI16Le/decU16Be/decU16LedecI32Be/decI32Le/decU32Be/decU32LedecI64Be/decI64Le/decU64Be/decU64LedecF32Be/decF32LedecF64Be/decF64LedecUtf8Unlike encoders, they are needed to invoke to get a
Decoderby an internal implementation reason.Also you can compose and customize decoders by
Decoder's monad to create your own decoder like this:Note that you need to match the process orders of your encoder and decoder, because it reads/writes a binary sequence by written order. If you consider the version of your data, you may use
Envelopeto append a version.