I think it is possible (and easy) to implement with
Data.ByteString.Builder. Just use the low-level interface: http://hacka
ge.haskell.org/package/bytestring-0.10.8.1/docs/Data-ByteString-
Builder-Extra.html#v:runBuilder
BufferWriter takes a buffer to write to and returns a continuation to
be called in case the buffer is too small. The idea is to allocate a
buffer, but reserve necessary space for length and checksum. Then run
the builder, get the resulting ByteString (or work directly with `Ptr
Word8`), calculate length and check sum and write then into the
reserved space.
Just be careful when using the low level API, and read the docs
carefully.
this might be of interest to you - the explanation is in German though:
http://nfa.imn.htwk-leipzig.de/HAL2015/programm/slides/breitner.pdf
Cheers,
Axel