Alexander V Vershilov | 23 Mar 06:35 2013
Picon

question about PutM patterns

Hello, cafe.

I have a big problem using builders, so currently I'm using own
builder based on Nettle one [1].
It uses Strict bytestring to build into and unchecked writes, thus
it's very unsafe, plus other
builders/PutM, developed rapidly so I like to switch to another one.
However I use some patterns that seems not implemented in other
builders, so I'd like to hear
advices how to implement it there or how I can write code without using them.
All of the patterns is done in order to have more performance and
gives a way to build complex
data without additional allocations.

1). Delayed input:
This unsafe pattern can be implemented in any PutM monad for any
constant sized value,
the idea is that we write a plaseholder and returns a funtion that
will write correct value to the
address when applied. This pattern is needed when we need to update
length or CRC sum after
content is written:

> test1 put = delayedWord16be >>= \ph -> someOtherStuff >> undelay ph calculateCRC

2). LookAhead:
Sometimes I need to know the length of the content to be written,
possibly I can write content
to ByteString, and calculate length and write it, however if resulting
type is not LBS it leads to
(Continue reading)


Gmane