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.
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
Serializer
andDeserializer
work onBuilder
model. It has these primitives below:And also serializing
string
as UTF-8 sequence is supported byencUtf8
/decUtf8
, as a composite builder.Their features are provided as each monad,
monadForCodeM
andmonadForDecoder
respectively. So you can combine them with using these monads andCatT
system.Encoder
An
Encoder<T>
denotes that a function transforming dataT
to aCode
, which writes bytes to anArrayBuffer
throughDataView
.There are utility functions to encode primitive data:
encUnit
- Does nothingencSum
- Useful to encode a sum typeencI8
/encU8
encI16Be
/encI16Le
/encU16Be
/encU16Le
encI32Be
/encI32Le
/encU32Be
/encU32Le
encI64Be
/encI64Le
/encU64Be
/encU64Le
encF32Be
/encF32Le
encF64Be
/encF64Le
encUtf8
Also you can compose and customize encoders by
CodeM
's monad to create your own encoder like this:Note that an
Encoder
serializes lazily. You need pass aCode
torunCode
to evaluate it.Decoder
A
Decoder<T>
denotes that a function parsingCode
to dataT
.There are utility functions to decode primitive data:
decSum
- Useful to decode a sum typefailDecoder
- Useful to report decoding errordecI8
/encU8
decI16Be
/decI16Le
/decU16Be
/decU16Le
decI32Be
/decI32Le
/decU32Be
/decU32Le
decI64Be
/decI64Le
/decU64Be
/decU64Le
decF32Be
/decF32Le
decF64Be
/decF64Le
decUtf8
Unlike encoders, they are needed to invoke to get a
Decoder
by 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
Envelope
to append a version.